-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollecting_Game.cpp
More file actions
66 lines (64 loc) · 1.04 KB
/
Collecting_Game.cpp
File metadata and controls
66 lines (64 loc) · 1.04 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
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
bool cmp(int a, int b) {
return a > b; // bigger element comes first
}
void solve(vector<int> &arr)
{
int n = arr.size();
vector<int> copy = arr;
vector<int> sum(n);
vector<int> hash(n);
hash[0] = n-1;
sort(copy.begin(),copy.end(),cmp);
sum = copy;
for(int i = n-2;i>=0;i--)
{
sum[i]+=sum[i+1];
}
for(int i=1;i<n;i++)
{
if(sum[i]>=copy[i-1])
{
hash[i] = hash[i-1];
}
else
{
hash[i] = n-i-1;
}
}
// Now
for(int i = 0;i<n;i++)
{
int idx = lower_bound(copy.begin(),copy.end(),arr[i],greater<int>()) - copy.begin();
cout<<hash[idx]<<" ";
}
cout<<endl;
return;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int> arr(n);
for (auto &a:arr)
cin>>a;
if(n==1)
{
cout<<0<<endl;
continue;
}
solve(arr);
}
return 0;
}