[CF1490E] Accidental Victory

Description

每个队伍初始时有一些代币,比赛每一轮随机挑两个代币数不为 0 的队伍,然后代币多的队伍获胜,代币少的队伍把代币全部给代币多的(代币数量相同则随机),直到最后只有一个队伍有代币,这个队伍获胜。求哪些队伍有可能获胜。

Solution

对于一个队伍,如果他消灭掉所有小于等于他的队伍,此时的代币数量不小于最大值,那么就能赢

#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve()
{
    int n;
    cin >> n;

    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x;
        y = i + 1;
        a[i] = {x, y};
    }

    sort(a.begin(), a.end());

    int sum = 0;
    int mx = a[n - 1].first;
    vector<int> b(n);
    vector<int> ans;
    int j = 0;
    for (int i = 0; i < n; i++)
    {
        if (j <= i)
            ++j, sum += a[i].first;
        while (j < n && sum >= a[j].first)
            sum += a[j].first, ++j;
        if (sum >= mx)
            ans.push_back(a[i].second);
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    cout << endl;
}

signed main()
{
    ios::sync_with_stdio(false);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

相关文章:

  • 2021-10-08
  • 2021-06-15
猜你喜欢
  • 2021-09-06
  • 2021-08-24
  • 2022-12-23
  • 2021-11-18
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案