coderforce 588A Duff and Meat(简单的贪心)

来源:互联网 发布:mapinfo地图数据下载 编辑:程序博客网 时间:2024/06/08 07:27
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define LL long longconst LL maxm=1e5+10;LL a[maxm],p[maxm];int main(){    LL n;    while(scanf("%lld",&n)!=EOF)    {        for(LL i=0;i<n;i++)        {            scanf("%lld%lld",&a[i],&p[i]);        }        LL sum=0;        for(LL i=0;i<n;)        {            LL cnt=0;            LL s=0;            for(LL j=i+1;j<n;j++)            {                if(p[i]<p[j])                {                    cnt++;                    s+=a[j];                }                else                {                    break;                }            }            sum+=(a[i]+s)*p[i];            i+=(cnt+1);        }        printf("%lld\n",sum);    }    return 0;}

0 0
原创粉丝点击