-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1904B.cpp
More file actions
62 lines (55 loc) · 1.53 KB
/
1904B.cpp
File metadata and controls
62 lines (55 loc) · 1.53 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
58
59
60
61
62
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
template<class K> using sset = tree<K, null_type, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
inline ll ceil0(ll a, ll b) {
return a / b + ((a ^ b) > 0 && a % b);
}
void setIO() {
ios_base::sync_with_stdio(0); cin.tie(0);
}
int main(){
setIO();
int T;
cin >> T;
for(int tt = 1; tt <= T; tt++){
int n;
cin >> n;
pii arr[n + 1];
for(int i = 1; i <= n; i++) cin >> arr[i].ff, arr[i].ss = i;
sort(arr + 1, arr + n + 1);
int nxt[n + 1];
ll sum[n + 1];
int ans[n + 1];
nxt[0] = sum[0] = 0;
for(int i = 1; i <= n; i++){
if(nxt[i - 1] >= i){
nxt[i] = nxt[i - 1];
sum[i] = sum[i - 1];
} else {
sum[i] = sum[i - 1] + arr[i].ff;
nxt[i] = i;
while(nxt[i] + 1 <= n && sum[i] >= arr[nxt[i] + 1].ff){
nxt[i]++;
sum[i] += arr[nxt[i]].ff;
}
}
ans[arr[i].ss] = nxt[i];
}
for(int i = 1; i <= n; i++) cout << ans[i] - 1 << " ";
cout << endl;
}
}