Submission #1013841

#TimeUsernameProblemLanguageResultExecution timeMemory
1013841MuhammetRice Hub (IOI11_ricehub)C++17
100 / 100
12 ms2520 KiB
#include <bits/stdc++.h> #include "ricehub.h" #define sz(s) (int)s.size() using namespace std; #define ll long long vector <int> v; bool f(int x, ll b, int n){ ll k = 0, ind = x/2, in = x-1; for(int i = 0; i < in; i++){ k += abs(v[ind]-v[i]); } while(in < n){ k += abs(v[in]-v[ind]); if(k <= b) return true; k -= (in-ind)*(v[ind+1]-v[ind]); k += (ind-(in-x+1))*(v[ind+1]-v[ind]); k -= (v[ind]-v[in-x+1]); in++; ind++; } return false; } int besthub(int n, int L, int a[], ll b){ for(int i = 0; i < n; i++) v.push_back(a[i]); int l = 2, r = n, ans = 1; while(l <= r){ int md = (l + r) / 2; if(f(md,b,n) == 1){ l = md+1; ans = md; } else { r = md-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...