[CodeForces1490E]Accidental Victory
Link:https://codeforces.com/problemset/problem/1490/E
description:
There are \(n\) players, every player has a power value. Every round, two players are randomly choosed, the one with higher power will win.(If their power is the same, one of them would win randomly.) And the looser's power will be 0.
please print the id of the possible winners in the same order of input.
My English is poor, please click the link.
solution:
There must be a player, such that anybody whose power less than him/her is absolutely looser. So Find him/her!
It's trivial to sort, traverse and sum, and the pivot is the one who's power greater than the current sum.
USE A COPY TO MAINTAIN THE INITIAL ORDER!
code:
#include<cstdio>
#include<algorithm>
const int N = 2e5 + 1;
typedef long long ll;
using namespace std;
int a[N], _a[N];
int main() {
int T; scanf("%d", &T);
while (T--) {
int n; scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
_a[i] = a[i];
}
sort(a + 1, a + 1 + n);
int cur;
ll sum = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] > sum)cur = i;
sum += a[i];
}
printf("%d\n", n - cur + 1);
for (int i = 1; i <= n; ++i)
if (_a[i] >= a[cur])
printf("%d ", i);
puts("");
}
}