Submission #259202

#TimeUsernameProblemLanguageResultExecution timeMemory
259202Hehehe쌀 창고 (IOI11_ricehub)C++14
100 / 100
30 ms3328 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define pi pair<int, int> #define sz(x) (int)((x).size()) //#define int long long #include "ricehub.h" const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll inf = 2e9; const ll mod = 1e9 + 7; const int N = 2e6 + 11; const ll INF64 = 3e18 + 1; const double eps = 1e-14; const double PI = acos(-1); //ifstream in(".in"); //ofstream out(".out"); ll x[N], s[N]; ll get(int x, int y){ if(x > y)return 0; return s[y] - s[x - 1]; } bool ok(int k, int n, ll b){ for(int l = 1; l <= n - k + 1; l++){ int r = l + k - 1; int m = (l + r) >> 1; //location ll cur = 0; cur = x[m]*(m - l) - get(l, m - 1); cur += get(m + 1, r) - x[m]*(r - m); if(cur <= b)return 1; } return 0; } int besthub (int n, int L, int X[], ll b){ for(int i = 1; i <= n; i++){ x[i] = X[i - 1]; } for(int i = 1; i <= n; i++){ s[i] = s[i - 1] + x[i]; } ll l = 1, r = n, ans = 1; while(l <= r){ int mid = (l + r) >> 1; if(ok(mid, n, b)){ ans = mid; l = mid + 1; }else r = mid - 1; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...