Cod sursa(job #952558)

Utilizator MagnvsDaniel Constantin Anghel Magnvs Data 23 mai 2013 17:47:33
Problema Bilute Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>

using namespace std;

ifstream fin("bilute.in");
ofstream fout("bilute.out");

typedef long long i64;

const i64 inf= (i64)1<<60;
const int nmax= 30000;

i64 sv[nmax+1], sc[nmax+1], sl[nmax+1];

int main(){
    int n;
    fin>>n;
    for (int i= 1; i<=n; ++i){
        fin>>sv[i]>>sl[i];
        sc[i]= sc[i-1]+sv[i]*i;
        sl[i]= sl[i-1]+sv[i]*sl[i];
        sv[i]= sv[i-1]+sv[i];
    }

    i64 ms= inf;
    int p= -1;
    for (int i= 1; i<=n; ++i){
        i64 aux= (i64)sv[i-1]*i-sc[i-1];
        aux+= sc[n]-sc[i]-(i64)(sv[n]-sv[i])*i;
        aux+= sl[i-1];
        aux+= sl[n]-sl[i];
        if (ms>aux){
            ms= aux;
            p= i;
        }
    }
    fout<<p<<" "<<ms<<"\n";

    return 0;
}