Pagini recente » Cod sursa (job #3216267) | Cod sursa (job #450860) | Cod sursa (job #1108395) | Cod sursa (job #2581973) | Cod sursa (job #2731797)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream fin("branza.in");
ofstream fout("branza.out");
int n, s, t, sum = 0, t2 = 0, kg_depoz = 0;
fin>>n>>s>>t;
stack <int> cost;
queue <int> cant;
while (n)
{
int c, p;
fin>>c>>p;
// cout<<c<<' '<<p<<endl;
n--;
if (cost.empty())
{
sum += c * p;
cost.push(c);
}
else if (t2 <= t && cost.top() * p + s * p < c * p)
{
kg_depoz += p;
cant.push(p);
t2++;
}
else if (t2 > 0)
{
sum += cost.top() * kg_depoz;
while (!cant.empty())
kg_depoz -= cant.front(), sum += kg_depoz * s, cant.pop();
cost.pop();
kg_depoz = 0;
}
else
{
cost.pop();
sum += c * p;
cost.push(c);
}
}
if (t2 > 0)
{
sum += cost.top() * kg_depoz;
sum += s * kg_depoz;
while (!cant.empty())
kg_depoz -= cant.front(), sum += kg_depoz * s, cant.pop();
}
fout<<sum;
}