Chri_K

奶酪工厂
#include <iostream>
using namespace std;
struct node
{
    int cost;
    int need;
}p[10010];
int main()
{
    int n,s;
    cin>>n>>s;
    for (int i=1;i<=n;i++)
    {
        cin>>p[i].cost>>p[i].need;
    }
    long long ans=0;
    int k;
     long long tmp;
     k=1; 
     for (int i=1;i<=n;i++)
       {
        if (p[i].cost<=p[k].cost+(i-k)*s)
           {
            k=i; 
           } 
        tmp=p[k].cost*p[i].need+(i-k)*s*p[i].need;
        ans+=tmp;
       }
       cout<<ans;
     return 0;
}

贪心

posted on 2020-10-19 16:40  Chri_K  阅读(52)  评论(0编辑  收藏  举报