#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
int n,m,i,j;
unsigned long long x,suma;
cin>>n>>m;
vector<unsigned long> gatunek(n);
vector<unsigned long long> wysokosc(n);
for (i=0;i<n;i++)
{
cin>>gatunek[i];
}
for (i=0;i<m;i++)
{
cin>>x>>x;
suma=0;
for (j=0;j<n;j++)
{
wysokosc[j]=wysokosc[j]+gatunek[j];
if (wysokosc[j]>x)
{
suma+=wysokosc[j]-x;
wysokosc[j]=x;
}
}
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 | #include <algorithm> #include <vector> #include <iostream> using namespace std; int main() { int n,m,i,j; unsigned long long x,suma; cin>>n>>m; vector<unsigned long> gatunek(n); vector<unsigned long long> wysokosc(n); for (i=0;i<n;i++) { cin>>gatunek[i]; } for (i=0;i<m;i++) { cin>>x>>x; suma=0; for (j=0;j<n;j++) { wysokosc[j]=wysokosc[j]+gatunek[j]; if (wysokosc[j]>x) { suma+=wysokosc[j]-x; wysokosc[j]=x; } } cout<<suma<<endl; } return 0; } |
English