Pagini recente » Cod sursa (job #1271056) | Cod sursa (job #1277329) | Cod sursa (job #1466967) | Cod sursa (job #2024967) | Cod sursa (job #2583075)
#include <fstream>
using namespace std;ifstream in("branza.in");ofstream out("branza.out");const int VM=1e5;int d[VM + 1],pret[VM + 1];int main(){long long n,s,t;long long cant,rez,st,dr;in>>n>>s>>t;rez=dr=0;st=1;for(int i=1;i<=n;i ++){in>>pret[i]>>cant;if(st<=dr&&i-d[st]==t+1)st++;while(st<=dr&&pret[i]<=pret[d[dr]]+s*(i-d[dr]))dr--;d[++dr]=i;rez+=cant*(pret[d[st]]+s*(d[dr]-d[st]));}out<<rez;return 0;}