Cod sursa(job #925196)

Utilizator andi23roscaRosca Andrei andi23rosca Data 24 martie 2013 13:43:48
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int A[15000],o,N,M,T,V,P,Q,i,j,s=0,x;
FILE *f= freopen ("datorii.in" , "r+",stdin);
FILE *g= freopen ("datorii.out" , "w+",stdout);
fscanf(f,"%d",&N);fscanf(f,"%d",&M);
for(i=1;i<=N;i++)
{
        fscanf(f,"%d",&A[i]);
}
for(i=1;i<=M;i++)
{
    fscanf(f,"%d",&o);
    if(o==0)
    {
        fscanf(f,"%d",&T);fscanf(f,"%d",&V);
        A[T]=A[T]-V;
    }
    else
    {
        fscanf(f,"%d",&P);fscanf(f,"%d",&Q);
        for(j=P;j<=Q;j++)
        {
            s=s+A[j];
        }
        fprintf(g,"%d\n",s);
        s=0;
    }
}

fclose(f);fclose(g);
return 0;
}