Official

C - World Tour Finals Editorial by en_translator


First, evaluate the current total score of each player. This can be done by accepting input and using a for statement to check if each problem is solved.

Next, find the minimum number of problems to satisfy the condition for each player.

Here, the following proposition holds.

  • In order for player \(i\) to minimize the number of problems to solve, they must solve those with highest scores first.

This is true because if a choice of problems does not satisfy the condition above, then there exists an unchosen problem whose score is higher than a chosen one, so replacing the former with the latter increases the total score.

Therefore, one can implement an algorithm that sorts the unsolved problems in descending order of scores, and solve the problems in order until the total score exceeds that of any other player.

Sample code (C++):

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

#define rep(i, x) for(int i = 0; i < (x); i++)

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	rep(i, m) cin >> a[i];
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	vector<int> now_sc(n);
	rep(i, n) now_sc[i] = i + 1;
	rep(i, n) rep(j, m) if(s[i][j] == 'o') now_sc[i] += a[j];
	int mx = *max_element(now_sc.begin(), now_sc.end());
	rep(i, n) {
		vector<int> remain;
		rep(j, m) if(s[i][j] == 'x') remain.push_back(a[j]);
		sort(remain.rbegin(), remain.rend());
		int ans = 0;
		while(now_sc[i] < mx) {
			now_sc[i] += remain[ans++];
		}
		cout << ans << endl;
	}
}

posted:
last update: