Pagini recente » Cod sursa (job #1295111) | Cod sursa (job #2008611) | Cod sursa (job #1817470) | Cod sursa (job #1633599) | Cod sursa (job #1788305)
#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;
}