Pagini recente » Cod sursa (job #1825498) | Cod sursa (job #3213850) | Cod sursa (job #328186) | Cod sursa (job #1788830) | Cod sursa (job #1498779)
#include <fstream>
using namespace std;
int stiva[100000];
int c[100000], p[100000];
int main()
{
ofstream out("branza.out");
ifstream in("branza.in");
int n, s, t, cost = 0;
int top = 0, bottom = 0;
in >> n >> s >> t;
for(int i=0; i < n; i++)
{
in >> c[i] >> p[i];
for(int i=bottom; i<top; i++)
c[stiva[i]] += s;
while(top>bottom && c[i] < c[stiva[top-1]])
top--;
stiva[top++] = i;
if(top-bottom > t)
bottom++;
cost += c[stiva[bottom]]*p[i];
}
out << cost;
}