Cod sursa(job #1788305)

Utilizator MgMnPopescu Matei MgMn Data 25 octombrie 2016 21:28:00
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
using namespace std;
int a[15001];
int n,i,x,y,z;
void plata(int k, int b){
    while(b!=0 && k>=1){
        if(b>a[k]){
            a[k]=0;
            b=b-a[k];
            k--;
        }
        else{
            a[k]=a[k]-b;
            b=0;
        }

}
}
ifstream f("datorii.in");
ofstream g("datorii.out");
int main()
{
    long m,j;
    long aux=0;
    f>>n>>m;
    for(i=1;i<=n;i++)
        f>>a[i];

    for(j=1;j<=m;j++){
            f>>x>>y>>z;

            if(x==1){
            for(i=y;i<=z;i++)
                aux=aux+a[i];
            g<<aux<<'\n';
            aux=0;
            }

            else
            plata(y,z);


    }
    return 0;
}