#include <bits/stdc++.h>
using namespace std;
int n, c, r;
vector<int> s, e, p;
int get_resp(vector<int> &v, int pos) {
vector<bool> alive(n, true);
int resp = 0;
for (int i = 0; i < c; i++) {
int l = -1, cnt_l = -1;
for (int j = 0; j < n; j++) {
if (alive[j]) cnt_l++;
if (cnt_l == s[i]) {
l = j;
break;
}
}
int win_id = l, cnt_r = 0;
for (int j = l; j < n; j++) {
if (cnt_r == e[i] - s[i] + 1) break;
if (alive[j]) {
cnt_r++;
if (v[j] > v[win_id]) {
win_id = j;
}
alive[j] = false;
}
}
alive[win_id] = true;
if (!alive[pos]) break;
}
return resp;
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
n = N; c = C; r = R; s.clear(); e.clear(); p.clear();
for (int i = 0; i < n; i++) {
p.push_back(K[i]);
}
for (int i = 0; i < c; i++) {
s.push_back(S[i]);
e.push_back(E[i]);
}
// 17 pontos
int best_resp = -1, best_pos = -1;
for (int pos = 0; pos < n; pos++) {
vector<int> vals;
for (int i = 0; i < pos; i++) {
vals.push_back(p[i]);
}
vals.push_back(r);
for (int i = pos; i < n - 1; i++) {
vals.push_back(p[i]);
}
int cur = get_resp(vals, pos);
if (cur > best_resp) {
best_resp = cur;
best_pos = pos;
}
}
return best_pos;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |