Pagini recente » Cod sursa (job #1838952) | Cod sursa (job #2497785) | Cod sursa (job #2057407) | Cod sursa (job #969549) | Cod sursa (job #641736)
Cod sursa(job #641736)
#include <iostream>
#include <fstream>
using namespace std;
int n,m;
float a[50],mat[30][3];
ifstream fin("datorii.in");
ofstream fout("datorii.out");
void citire()
{
int i,j,k,ok;
fin>>n>>m;
while ((n<1) || (n>15000) || (m<=0)|| (m>100000))
fin>>n>>m;
ok=1;
while (ok==1)
{
for (i=1;i<=n;i++)
{
fin>>a[i];
if (i==n) ok=0;
if (a[i]<=0) ok=0;
}
}
for (j=1;j<=m;j++)
for (k=1;k<=3;k++)
fin>>mat[j][k];
}
float achitare(int t,float v)
{
a[t]=a[t]-v;
return a[t];
}
void interogare(int p,int q)
{
int s=0,i;
for (i=p;i<=q;i++)
s=s+a[i];
fout<<s<<"\n";
}
void test()
{
int i,j;
for (i=1;i<=m;i++)
{
if (mat[i][1]==0) achitare(mat[i][2],mat[i][3]);
if (mat[i][1]==1) interogare(mat[i][2],mat[i][3]);
}
}
int main()
{
citire();
test();
return 0;
}