Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.2 kB
3
Indexable
Never
//MY CODE
void solve(){
    ll n;cin>>n;
    ipar(a,n);
    ipar(b,n);
    vector<ll>pre(n);
    vector<ll>res(n),full(n);///full[i]-no of cups i person will drink to his full capacity bi
    pre[0]=b[0];
    for(int i=1;i<n;i++)
        pre[i]=pre[i-1]+b[i];
    for(int i=0;i<n;i++){
        auto j=upper_bound(all(pre),a[i]+(i>0?pre[i-1]:0))-pre.begin()-1;
        full[i]++;
        full[j]--;
        res[j]+=a[i]-(pre[j-1]-(i>0?pre[i-1]:0));
    }
    for(int i=1;i<n;i++)
        full[i]+=full[i-1];
    for(int i=0;i<n;i++){
        res[i]+=(full[i]*b[i]);
    }
    flush_vec(res);
}


//OFFICIAL EDITORIAL
int main() {
  int t;cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<li> a(n), b(n);
    for (auto& x : a) cin >> x;
    for (auto& x : b) cin >> x;
    vector<li> sum(n + 1);
    for (int i = 0; i < n; ++i) sum[i + 1] = sum[i] + b[i];
    vector<li> cnt(n + 1), add(n + 1);
    for (int i = 0; i < n; ++i) {
      int j = upper_bound(sum.begin(), sum.end(), a[i] + sum[i]) - sum.begin() - 1;
      cnt[i] += 1;
      cnt[j] -= 1;
      add[j] += a[i] - sum[j] + sum[i];
    }
    for (int i = 0; i < n; ++i) {
      cout << cnt[i] * b[i] + add[i] << ' ';
      cnt[i + 1] += cnt[i];   
    }
    cout << '\n';
  }
}
Leave a Comment