Pagini recente » Cod sursa (job #2570773) | Cod sursa (job #2529155) | Cod sursa (job #1932607) | Cod sursa (job #2219404) | Cod sursa (job #3251211)
#include <iostream>
#include<deque>
#include<fstream>
using namespace std;ifstream fin("branza.in");ofstream fout("branza.out");
int n,dep,m,i,v[100001],k;deque<int>q;long long s;
int main()
{fin>>n>>dep>>m;
for(i=1;i<=n;i++){fin>>v[i]>>k;
while(!q.empty()&&v[q.back()]+dep*(i-q.front())>=v[i])q.pop_back();q.push_back(i);
while(!q.empty()&&i-q.front()>=m)q.pop_front();
s+=(v[q.front()]+(i-q.front())*dep)*k;cout<<s<<" "<<q.front()<<" "<<v[q.front()]<<"\n";
}fout<<s;
return 0;
}
/*
5 10 3
12 1
21 2
27 4
45 5
52 3
*/
//1