Cod sursa(job #1001895)

Utilizator Gusti666Lucaciu Catalin Gusti666 Data 26 septembrie 2013 15:19:05
Problema Next Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#define nmax 25000

using namespace std;
ifstream f("hacker3.in");
ofstream g("hacker3.out");
long long i,n,cost1,k,p;
int a[nmax],b[nmax];

void prelucreaza ()  {
    if(a[i]+cost1>b[i]) cost1+=b[i];
            else           cost1=cost1+a[i]+cost1;
}

void deschide (){
    f.open("hacker3.in");
}
void inchide () { f.close();
}
int main()
{f>>n;
f.close();


while(n>25000){
f.open("hacker3.in");

f>>p;


for(i=1;i<=(n-25000);i++){
    f>>p;f>>p;
}
for(i=1;i<=25000;i++){
    f>>a[i];f>>b[i];

}
for(i=25000;i>=1;i--){

if(a[i]+cost1>b[i]) cost1+=b[i];
            else           cost1=cost1+a[i]+cost1;
}
f.close();
n-=25000;
}
f.open("hacker3.in");
f>>p;

for(i=1;i<=n;i++){
f>>a[i];f>>b[i];}

for(i=n;i>=1;i--){
if(a[i]+cost1>b[i]) cost1+=b[i];
            else           cost1=cost1+a[i]+cost1;

}


g<<cost1;
f.close();








    return 0;
}