#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int n, m, suma = 0, a ,b = 0, i = 0,x,y,k = 0;
int taba[100000], tabb[100000];
cin>>n>>m;
while(i<n)
{
cin>>x;
taba[i] = x;
i++;
}
i = 0;
while(a<=m)
{
suma = 0;
cin>>a>>b;
for(y = 0;y<n;y++)
{
tabb[y] += taba[y];
if(tabb[y]>b)
{
suma += tabb[y] - b;
tabb[y] = b;
}
}
cout<<suma<<endl;
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int n, m, suma = 0, a ,b = 0, i = 0,x,y,k = 0; int taba[100000], tabb[100000]; cin>>n>>m; while(i<n) { cin>>x; taba[i] = x; i++; } i = 0; while(a<=m) { suma = 0; cin>>a>>b; for(y = 0;y<n;y++) { tabb[y] += taba[y]; if(tabb[y]>b) { suma += tabb[y] - b; tabb[y] = b; } } cout<<suma<<endl; } return 0; } |
English