This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int find_best(int n) {
int mx_sum = 0;
for(int k = 0; k < 30; k++) {
auto v = ask(rand() % n);
mx_sum = max(mx_sum, v[0]+v[1]);
}
for(int i = 0; i < n; i++) {
auto v = ask(i);
int sum = v[0]+v[1];
if(sum == 0) {
return i;
}
if(sum == mx_sum) {
int l = i, r = n-1;
while(l < r) {
int m = (l+r+1)/2;
auto v_p = ask(m);
int sum_p = v_p[0]+v_p[1];
if(sum_p < mx_sum || v_p[0] > v[0]) {
r = m-1;
}
else {
l = m;
}
}
i = l;
}
}
return 0;
}
/*
5
2 2 2 1 2
8
3 3 2 3 3 2 1 3
sample:
8
3 2 3 1 3 3 2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |