Submission #1040045

#TimeUsernameProblemLanguageResultExecution timeMemory
1040045khanhtbRice Hub (IOI11_ricehub)C++14
100 / 100
11 ms2680 KiB
// #pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define pf push_front #define vi vector<ll> #define vii vector<vi> #define pll pair<ll, ll> #define vpll vector<pll> #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; const ll mod = 998244353; const ll inf = 1e18; const ll blocksz = 320; const ll N = 2e5+8; int n; ll a[N],b,l; bool check(ll m){ ll suml = 0, sumr = 0, val_mid = 0; ll lenl = (m+1)/2, lenr = m-lenl; for(int i = 1; i <= (m+1)/2; i++) suml += a[i]; for(int i = (m+1)/2+1; i <= m; i++) sumr += a[i]; val_mid = a[(m+1)/2]; ll ans = inf; for(int i = 1; i <= n-m+1; i++){ ans = min(ans,sumr-lenr*val_mid+val_mid*lenl-suml); val_mid = a[(m+1)/2+i]; suml -= a[i], suml += val_mid; sumr -= val_mid, sumr += a[i+m]; } return (ans <= b); } int besthub(int R, int L, int X[], ll B){ n = R, l = L, b = B; for(int i = 1; i <= n; i++) a[i] = X[i-1]; int l = 1, r = n; int ans = 0; while(l <= r){ ll m = l+r>>1; if(check(m)){ ans = m; l = m+1; } else r = m-1; } return ans; }

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |         ll m = l+r>>1;
      |                ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...