제출 #1185035

#제출 시각아이디문제언어결과실행 시간메모리
1185035al95ireyiz쌀 창고 (IOI11_ricehub)C++20
100 / 100
8 ms1552 KiB
//*** Bismillah ***// #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #if !defined(ONLINE_JUDGE) and !defined(EVAL) #include "template/debug.h" #else #define d(x...) #endif #define fr first #define sc second #define in insert #define ll long long #define pb push_back #define vll vector<ll> #define pll pair<ll,ll> #define all(x)x.begin(),x.end() const ll INF = 1e9; const ll INFL = 1e18; const ll MOD = 1e9+7; // const ll MOD = 998244353; const ll maxn = 1e5+5; ll n,m,k=0; #include "ricehub.h" ll a[maxn]; ll f(ll x){ // x denesini min qiymete goturmeyin en yaxsi yolu en yaxin x denesinin medianini goturmekdi ll cv = INFL, md = x/2; // ilki elimle hesablayiram ll cm = 0; for(ll i=1;i<=x;i++){ cm += abs(a[i] - a[md]); } cv = min(cv, cm); ll l=1, r=x, i = md, lsay = md - 1, rsay = r - md; while(r < n){ l ++, r ++, i ++; cm -= abs(a[l-1] - a[i-1]); cm += abs(a[r] - a[i]); cm += abs(a[i-1] - a[i]) * lsay; cm -= abs(a[i-1] - a[i]) * rsay; cv = min(cv, cm); } return cv; } int besthub(int _R, int _L, int _X[], ll _B){ n = _R, m = _L, k = _B; // memset(a, INF, sizeof(a)); for(ll i=0;i<maxn;i++) a[i] = INFL; for(ll i=1;i<=n;i++) a[i] = _X[i-1]; // Cavab - duyu zeminleri ucun binary search: int l = 0, r = n, cv=0; while(l <= r){ ll md = (l + r) >> 1; if(f(md) <= k) l = md + 1, cv = md; else r = md - 1; } return cv; } // void _(){ // ll x, b, c; // cin>>x>>b>>c; // int d[x]; // for(ll i=0;i<x;i++) cin>>d[i]; // cout<<besthub(x, b, d, c)<<'\n'; // } // signed main(){ // ll tm=clock(); // cin.tie(0)->sync_with_stdio(0); // ll t=1; // // cin>>t; // while(t--) _(); // cerr<<"\n\033[1;31mTime: \033[1;30m" // <<(double)(clock()-tm)/1000000<<"\033[1;32m seconds\n"; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...