#include <bits/stdc++.h> using namespace std;
int max_diff = -1; vector<string> scores;
int getValue(int idx) { return 10 - idx; }
void calScore(vector<int> apeach, vector<int> ryan) { int diff = 0; int total_apeach = 0; int total_ryan = 0; for (int i = 0; i < 11; i++) { if (apeach[i] == 0 && ryan[i] == 0) { continue; }
if (apeach[i] >= ryan[i]) { total_apeach += getValue(i); } else { total_ryan += getValue(i); } }
if (total_ryan > total_apeach) { diff = total_ryan - total_apeach; } else { return; }
string str; for (int i : ryan) { str += i + '0'; } reverse(str.begin(), str.end());
if (diff > max_diff) { max_diff = diff; scores.clear(); scores.push_back(str); } else if (diff == max_diff) { scores.push_back(str); } }
void back_tracking(int depth, int idx, int n, vector<int>& apeach, vector<int>& ryan) { if (idx > 10) { return; }
if (depth == n) { calScore(apeach, ryan); return; }
ryan[idx] += 1; back_tracking(depth + 1, idx, n, apeach, ryan); ryan[idx] -= 1; back_tracking(depth, idx + 1, n, apeach, ryan); }
vector<int> solution(int n, vector<int> info) { vector<int> answer; vector<int> ryan = vector<int>(11, 0); back_tracking(0, 0, n, info, ryan);
if (max_diff == -1) { answer.push_back(-1); } else { sort(scores.begin(), scores.end(), greater<string>()); string str = scores[0]; reverse(str.begin(), str.end()); for (int i = 0; i < str.size(); i++) { answer.push_back(str[i] - '0'); } } return answer; }
|