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

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
const 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;
}

你可能感兴趣的:(coderforce 588A Duff and Meat(简单的贪心))