#include <cstdio> #include <vector> #include <algorithm> using namespace std; inline long long maxz(long long a){ return a < 0 ? 0 : a; } int main(){ int n, m; scanf("%d %d", &n, &m); vector<long long> kli(n+1); vector<int> piece(m); kli[0] = 0; for(int i = 1; i < n+1; ++i){ scanf("%lld", &kli[i]); } for(int i = 0; i < n; ++i){ kli[i] = kli[i+1] - kli[i]; } for(int i = 0; i < m; ++i){ scanf("%d", &piece[i]); } long long czek; long long last; long long curr; for(int i = 0; i < m; ++i){ czek = 0; last = 0; for(int j = 0; j < n; ++j){ curr = maxz(last - kli[j] + piece[i]); czek += curr; last = curr; } printf("%lld\n", czek); } 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 40 41 42 43 44 45 46 47 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; inline long long maxz(long long a){ return a < 0 ? 0 : a; } int main(){ int n, m; scanf("%d %d", &n, &m); vector<long long> kli(n+1); vector<int> piece(m); kli[0] = 0; for(int i = 1; i < n+1; ++i){ scanf("%lld", &kli[i]); } for(int i = 0; i < n; ++i){ kli[i] = kli[i+1] - kli[i]; } for(int i = 0; i < m; ++i){ scanf("%d", &piece[i]); } long long czek; long long last; long long curr; for(int i = 0; i < m; ++i){ czek = 0; last = 0; for(int j = 0; j < n; ++j){ curr = maxz(last - kli[j] + piece[i]); czek += curr; last = curr; } printf("%lld\n", czek); } return 0; } |