Pagini recente » Cod sursa (job #1968225) | Cod sursa (job #639782) | Clasamentul arhivei Infoarena Monthly | Cod sursa (job #2871834) | Cod sursa (job #1781022)
#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;
}
}
}
fstream 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;
}