Pagini recente » Cod sursa (job #2382990) | Cod sursa (job #2847439) | Cod sursa (job #908262) | Cod sursa (job #1235921) | Cod sursa (job #762565)
Cod sursa(job #762565)
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
ofstream fout("hacker3.out");
#define rFactor 20000
struct task{
int a, b;
}aux;
stack<task> s;
long long n, pd, lastpd, mfactor;
int main() {
int i, j, a, b;
ifstream f("hacker3.in");
f >> n;
f.close();
mfactor = n % rFactor;
for (j = 1; j <= n / rFactor; ++j) {
ifstream fin("hacker3.in");
fin >> n;
for (i = 1; i <= n; ++i) {
fin >> a >> b;
if (i <= mfactor + (n / rFactor - j + 1) * rFactor && i > mfactor + (n / rFactor - j) * rFactor) {
aux.a = a;
aux.b = b;
//cerr << a << " " << b << "\n";
s.push(aux);
}
}
while (!s.empty()) {
aux = s.top();
s.pop();
pd = min (aux.b + lastpd, aux.a + 2 * lastpd);
lastpd = pd;
}
fin.close();
}
//cerr << pd << "\n";
ifstream st("hacker3.in");
st >> n;
for (j = 1; j <= n % rFactor; ++j) {
st >> a >> b;
aux.a = a;
aux.b = b;
s.push(aux);
}
while (!s.empty()) {
aux = s.top();
s.pop();
pd = min (aux.b + lastpd, aux.a + 2 * lastpd);
lastpd = pd;
}
st.close();
fout << pd << "\n";
return 0;
}