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 sqrtn = 500;
int find_best(int n) {
sqrtn = min(sqrtn, n);
int max_sum = 0;
for (int i = 0; i < sqrtn; i++)
{
auto a = ask(i);
max_sum = max(max_sum, a[0] + a[1]);
if (a[0] + a[1] == 0) {
return i;
}
}
for (int i = sqrtn; i < n; i++) {
auto val = ask(i);
if (val[0] + val[1] != max_sum) {
if (val[0] + val[1] == 0)
return i;
continue;
}
int rval = val[1];
int l = i, r = n - 1, ans = -1;
while (l < r) {
int mid = (l + r) / 2;
auto midval = ask(mid);
if (midval[0] + midval[1] != max_sum || midval[1] < rval)
r = mid;
else
l = mid + 1, ans = mid;
}
i = ans;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |