贪心思想:维护每一个点上的两种决策:取这个点的价值还是取这个点前面权值最小的点的价值。取完这个点后,更新最小值并处理下一个点。
证明:因为储存价值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.