Cod sursa(job #254429)

Utilizator harababurelPuscas Sergiu harababurel Data 7 februarie 2009 12:05:02
Problema Cuburi2 Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 1.27 kb
#include <iostream>
#include <fstream>
using namespace std;
int main() {
    int n,m,i,mij;
    int v[100000],j;
    int x,y,dest=0,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];
             }
    if(n%2==1) {
               dest=int(n/2)+1;
               }
    else {
         dest=n/2;
         }
    
    
    for(i=1; i<=m; i++) {
             f>>x>>y;
             cost=0;
             if(x>=y) {
                      mij=x-y;
                      }
             else {
                  mij=y-x;
                  }
             if(mij%2==1) {
                          dest=(mij+1)/2 + (x-1);
                          }
             else {
                  dest=(mij/2)+(x-1);
                  }
             
             
             for(j=x; j<=y; 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;
}