#include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <algorithm> #include <cstring> #include <ctime> #include <cassert> using namespace std; #define pb push_back #define mp make_pair #define pii pair<int,int> #define fi first #define se second #define vi vector<int> #define vpii vector<pii> #define SZ(x) ((int)(x.size())) #define DBG cerr << "debug here" << endl; #define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl; typedef long long ll; const int INF = 1e9; const int N = 2e5+10; const int M = 2e5+10; ll t[N]; ll res[M]; int main() { int n, m; scanf("%d %d", &n, &m); ll sumt = 0; for (int i = 1; i <= n; ++i) { scanf("%lld", &t[i]); sumt += t[i]; } vector<pii> ds(m); for (int i = 0; i < m; ++i) { scanf("%d", &ds[i].fi); ds[i].se = i; } sort(ds.begin(), ds.end()); for (int pid = 0; pid < m; ++pid) { ll sumf = 0; int d = ds[pid].fi; ll f = 0; for (int i = 1; i <= n; ++i) { f = max(f+d, t[i]); sumf += f; } res[ds[pid].se] = sumf-sumt; } for (int i = 0; i < m; ++i) { printf("%lld\n", res[i]); } 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <algorithm> #include <cstring> #include <ctime> #include <cassert> using namespace std; #define pb push_back #define mp make_pair #define pii pair<int,int> #define fi first #define se second #define vi vector<int> #define vpii vector<pii> #define SZ(x) ((int)(x.size())) #define DBG cerr << "debug here" << endl; #define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl; typedef long long ll; const int INF = 1e9; const int N = 2e5+10; const int M = 2e5+10; ll t[N]; ll res[M]; int main() { int n, m; scanf("%d %d", &n, &m); ll sumt = 0; for (int i = 1; i <= n; ++i) { scanf("%lld", &t[i]); sumt += t[i]; } vector<pii> ds(m); for (int i = 0; i < m; ++i) { scanf("%d", &ds[i].fi); ds[i].se = i; } sort(ds.begin(), ds.end()); for (int pid = 0; pid < m; ++pid) { ll sumf = 0; int d = ds[pid].fi; ll f = 0; for (int i = 1; i <= n; ++i) { f = max(f+d, t[i]); sumf += f; } res[ds[pid].se] = sumf-sumt; } for (int i = 0; i < m; ++i) { printf("%lld\n", res[i]); } return 0; } |