#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); int tab[n]; unsigned long long int stan[n]; for( int i = 0; i < n; i ++ ) { scanf("%d", &tab[i]); stan[i] = 0; } unsigned long long int D[m+4]; D[0] = 0; for( int z = 1; z <= m; z ++ ) { unsigned long long int b; scanf("%lld %lld", &D[z], &b); unsigned long long int wyn = 0; for( int i = 0; i < n; i ++ ) { stan[i] = (D[z] - D[z-1])*tab[i] + stan[i]; } for( int i = 0; i < n; i ++ ) { if( stan[i] > b ) wyn += stan[i] - b; stan[i] = min(stan[i],b); } printf("%lld\n", wyn); } 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 <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); int tab[n]; unsigned long long int stan[n]; for( int i = 0; i < n; i ++ ) { scanf("%d", &tab[i]); stan[i] = 0; } unsigned long long int D[m+4]; D[0] = 0; for( int z = 1; z <= m; z ++ ) { unsigned long long int b; scanf("%lld %lld", &D[z], &b); unsigned long long int wyn = 0; for( int i = 0; i < n; i ++ ) { stan[i] = (D[z] - D[z-1])*tab[i] + stan[i]; } for( int i = 0; i < n; i ++ ) { if( stan[i] > b ) wyn += stan[i] - b; stan[i] = min(stan[i],b); } printf("%lld\n", wyn); } return 0; } |