CF1814C 题解
思路
挺像某些排队接水的问题的。
首先肯定让询问次数越多的小球排在越前面,所以要从大到小排序再枚举。然后看看 和 中哪个排队时间短就去那一堆。
代码
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t, n, s1, s2, m1, m2, ans1[200005], ans2[200005];
pii a[200005];
int main () {
ios::sync_with_stdio (0); cin.tie (0);
cout.tie (0);
cin >> t;
while (t --) {
cin >> n >> s1 >> s2;
for (int i = 1; i <= n; ++ i)
cin >> a[i].first, a[i].second = i;
sort (a + 1, a + n + 1, greater <pii> ());
m1 = m2 = 1;
for (int i = 1; i <= n; ++ i)
if (m1 * s1 < m2 * s2)
ans1[m1] = a[i].second, ++ m1;
else
ans2[m2] = a[i].second, ++ m2;
cout << m1 - 1 << ' ';
for (int i = 1; i < m1; ++ i)
cout << ans1[i] << ' ';
cout << '\n' << m2 - 1 << ' ';
for (int i = 1; i < m2; ++ i)
cout << ans2[i] << ' ';
cout << '\n';
}
return 0;
}

浙公网安备 33010602011771号