Cod sursa(job #254298)

Utilizator harababurelPuscas Sergiu harababurel Data 7 februarie 2009 10:52:23
Problema Cuburi2 Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 0.79 kb
#include <iostream>
#include <fstream>
using namespace std;
int main() {
    int n,m,i;
    int v[100000],j;
    int x,y,dest,cost=0;
    ifstream f;  f.open("cuburi2.in");
    ofstream g;  g.open("cuburi2.out");
    f>>n>>m;
    for(i=1; i<=n; i++) {
             f>>v[i];
             }
    dest=int(n/2);
    for(i=1; i<=m; i++) {
             f>>x>>y;
    
             for(j=x+1; j=y-1; j++) {
                        if(j>dest) {
                                   cost=cost+(j-dest); 
                                   }
                        else if(j<dest) {
                             cost=cost+(dest-j);
                             }
                        }
             g<<dest<<" "<<cost<<endl;
             }
    f.close();
    g.close();
    return 0;
}