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>
#define fs first
#define sc second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pi;
vector<pi> srt;
int mx;
int find_best(int n)
{
for(int i=0;i<min(n,500);i++)
{
vi ans=ask(i);
srt.pb({ans[0]+ans[1],i});
}
sort(all(srt));
mx=srt.back().fs;
srt.clear();
int st=0;
while(st<n)
{
vi ans=ask(st);
if(ans[0]+ans[1]!=mx)
{
srt.pb({ans[0]+ans[1],st});
st++;
}
else
{
int l=st,r=n-1,pos;
while(l<=r)
{
int mid=(l+r)>>1;
vi new_ans=ask(mid);
if(new_ans[0]+new_ans[1]!=mx or (new_ans[0]+new_ans[1]==mx and new_ans[1]<ans[1]))
r=mid-1;
else
{
l=mid+1;
pos=mid;
}
}
st=pos+1;
}
}
sort(all(srt));
return srt[0].sc;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:54:10: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | st=pos+1;
| ~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |