bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】

贪心,一边读入一边更新mn,用mn更新答案,mn每次加s

#include<iostream>
#include<cstdio>
using namespace std;
int n,s,mn=1e9;
long long ans;
int main()
{
	scanf("%d%d",&n,&s);
	for(int i=1,w,c;i<=n;i++)
	{
		scanf("%d%d",&w,&c);
	 	mn+=s;
		mn=min(mn,w);
	 	ans+=1ll*mn*c;
	}
	printf("%lld\n",ans);
	return 0;
}
posted @ 2018-09-04 21:35  lokiii  阅读(68)  评论(0编辑  收藏  举报