# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47719 | 2018-05-06T17:54:45 Z | SinByCos | 커다란 상품 (IOI17_prize) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "prize.h" using namespace std; const int MAXN = 2e5 + 5; int find_best(int n){ int sum = 0, p = 500; for(int i=0; i<min(n, 500); ++i){ vector<int> v = ask(i); sum = max(sum, v[0] + v[1]); if(v[0] + v[1] == 0) return i; } while(p < n){ vector<int> v = ask(p); if(v[0] + v[1] == 0) return p; int lo = p + 1, hi = n - 1, mid; if(v[0] + v[1] == sum){ while(lo <= hi){ mid = (lo + hi)/2; vector<int> ans = ask(mid); if(ans[0] + ans[1] == 0) return mid; if(lo == hi) break; if(ans[0] + ans[1] < sum) hi = mid; else if (ans[0]+ans[i] > sum) assert(false); else{ if(v[1] - ans[1] > 0) hi = mid - 1; else lo = mid + 1; } } p = lo + 1; } else p++; } }