【题目链接】
【算法】
前缀和 + 堆
【代码】
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MAXN = 1e5; ll N,i,ans,sum,tmp; ll v[MAXN+10],t[MAXN+10]; priority_queue<ll,vector<ll>,greater<ll> > q; template <typename T> inline void read(T &x) { ll f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; } for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= f; } template <typename T> inline void write(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) write(x/10); putchar(x%10+'0'); } template <typename T> inline void writeln(T x) { write(x); puts(""); } int main() { read(N); for (i = 1; i <= N; i++) read(v[i]); for (i = 1; i <= N; i++) read(t[i]); for (i = 1; i <= N; i++) { ans = 0; q.push(sum+v[i]); sum += t[i]; while (!q.empty() && q.top() <= sum) { tmp = q.top(); q.pop(); ans += tmp - (sum - t[i]); } ans += q.size() * t[i]; write(ans); if (i < N) putchar(' '); } puts(""); return 0; }