贪心思想:维护每一个点上的两种决策:取这个点的价值还是取这个点前面权值最小的点的价值。取完这个点后,更新最小值并处理下一个点。

证明:因为储存价值s固定,所以贪心策略成立。

CODE

Program Yogfac;//By_Poetshy
Var
	i,n,m								:Longint;
	re,ans,p,q							:Int64;
	
BEGIN
	ans:=0;
	readln(n,m);re:=maxlongint>>1;
	for i:=1 to n do 
		begin
			readln(p,q);
			inc(re,m);
			if re<p then inc(ans,re*q) else 
				begin
					re:=p;
					inc(ans,p*q);
				end;
		end;
	writeln(ans);
END.

相关文章:

  • 2021-10-13
  • 2021-12-21
  • 2021-12-25
  • 2021-11-15
  • 2021-12-14
  • 2021-12-14
  • 2021-12-07
猜你喜欢
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案