-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path279-tea-tasting.cpp
More file actions
57 lines (54 loc) · 1.66 KB
/
Copy path279-tea-tasting.cpp
File metadata and controls
57 lines (54 loc) · 1.66 KB
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
/*
* Tea Tasting [1795C]
* Problem: https://codeforces.com/problemset/problem/1795/C
* Verdict: ACCEPTED Solved: 2025-03-20
* Language: C++23 (GCC 14-64, msys2)
* Runtime: 171 ms Memory: 3500 KB
* Tags: binary search, data structures, implementation
* Author: BidoTeima
* Source: https://codeforces.com/contest/1795/submission/311530666
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
ll a[n],pre[n],b[n];
for(auto&i:a)cin>>i;
for(int i = 0; i < n; i++){
cin>>b[i];
pre[i]=b[i];
if(i)pre[i]+=pre[i-1];
}
ll semi[n]{}; // semi drinks (i.e. tot.. + semi[i])
int full[n+1]{}; // full drinks (i.e. tot.. + b[i] x full[i])
for(int i = 0; i < n; i++){
// biggest index j such that a[i] >= pre[j] - pre[i - 1] (b[i]+b[i+1]+...+b[j])
// pre[j] <= a[i] + pre[i - 1]
int idx = upper_bound(pre + i, pre + n, a[i] + (i==0?0:pre[i-1])) - pre;
if(idx == i){
// none exists, just move on with life :(
semi[i] += a[i];
}else{
++full[i];
--full[idx];
if(idx < n){
ll rem = a[i] - (pre[idx-1] - (i==0?0:pre[i-1]));
semi[idx] += rem;
}
}
}
for(int i = 1; i < n; i++)full[i]+=full[i-1];
for(int i = 0; i < n; i++) cout<<b[i]*full[i]+semi[i]<<' ';
cout<<'\n';
}
return 0;
}