#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200010; ll dp[N]; ll t[N]; ll d[N]; int main() { ios_base::sync_with_stdio(0); int n, m; ll w = 0; cin >> n >> m; for(int i=1; i <= n; ++i) cin >> t[i]; for(int i=0; i < m; ++i) { w = 0; int d; cin >> d; for(int j=1; j <= n; ++j) { dp[j] = max(dp[j-1] + d, t[j]); w += dp[j] - t[j]; } cout << w << "\n"; } }
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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200010; ll dp[N]; ll t[N]; ll d[N]; int main() { ios_base::sync_with_stdio(0); int n, m; ll w = 0; cin >> n >> m; for(int i=1; i <= n; ++i) cin >> t[i]; for(int i=0; i < m; ++i) { w = 0; int d; cin >> d; for(int j=1; j <= n; ++j) { dp[j] = max(dp[j-1] + d, t[j]); w += dp[j] - t[j]; } cout << w << "\n"; } } |