#include <iostream>
using namespace std;
int t[1000000],ta[1000000],tab[1000000],n,m,d,b,s,i;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>t[i];
tab[i]=t[i];
}
for(int e=0;e<m;e++)
{
cin>>d>>b;
for(int j=0;j<n;j++)
{
ta[j]=b;
s+=tab[j]-ta[j];
}
if(s<0) s=0;
cout<<s<<endl;
s=0;
for(int h=0;h<n;h++)
{
tab[h]=t[h]+b;
}
}
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 | #include <iostream> using namespace std; int t[1000000],ta[1000000],tab[1000000],n,m,d,b,s,i; int main() { cin>>n>>m; for(int i=0;i<n;i++) { cin>>t[i]; tab[i]=t[i]; } for(int e=0;e<m;e++) { cin>>d>>b; for(int j=0;j<n;j++) { ta[j]=b; s+=tab[j]-ta[j]; } if(s<0) s=0; cout<<s<<endl; s=0; for(int h=0;h<n;h++) { tab[h]=t[h]+b; } } return 0; } |
English