제출 #155836

#제출 시각아이디문제언어결과실행 시간메모리
155836m1sch3f쌀 창고 (IOI11_ricehub)C++17
17 / 100
268 ms1912 KiB
#include <bits/stdc++.h> using namespace std; // types - only for stuff used a lot using ll = long long; #define vv vector #define Pp pair // IO #define get(x) scanf("%d",&x) #define getl(x) scanf("%lld",&x); // Operations #define pb push_back #define pob pop_back #define sz(a) int(a.size()) #define re(a,b) a=max(a,b) // relax #define ri(a,b) a=min(a,b) // relaxi // Debugging #ifndef LOCAL #define cerr if (0) cerr #else #define cerr cout #endif #define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; } #define printv(vec) {for (int _ : vec) cerr<<_<<" "; cerr<<endl;} const int mod = 1e9+7, oo = 1e9; const ll loo = 1e18; // Functions ll modpow(ll a, ll b) { ll ans = 1; // faster modpow than recursive for (; b; b/=2,a=a*a%mod) if (b&1) ans = (ans*a)%mod; return ans; } ll gcd(ll a, ll b) { while (a) b%=a,swap(a,b); return b; } #define bitcount __builtin_popcountll #define f(i,a,b) for (int i = a; i < b; i++) #define fr(i,a,b) for (int i = b-1; i >= a; i--) /* ALRIGHT HACKERS, THIS IS WHERE THE ACTUAL CODE BEGINS */ const bool DEBUG = 1; using pll = pair<ll,ll>; int besthub(int N, int L, int rem[], ll B) { sort(rem,rem+N); ll C[N]; f(i,0,N) C[i] = i?rem[i]+C[i-1]:rem[i]; vector<int> X(N); f(i,0,N) X[i] = rem[i]; auto sum = [&](int i, int j) { if (i>j) return 0LL; return C[j]-(i?C[i-1]:0); }; auto fu = [&](int i, ll l) { // to the left int x = -distance(lower_bound(begin(X),end(X),X[i]-l),begin(X)); int y = -distance(upper_bound(begin(X),end(X),X[i]+l),begin(X))-1; return pll(1LL*(2*i-x-y)*X[i]-sum(x,i-1)+ sum(i+1,y),y-x+1); }; ll ans = 1; f(i,0,N) { ll lo = 0, hi = L; while (lo <= hi) { ll mid = (lo+hi)>>1; if (fu(i,mid).first <= B) lo = mid+1; else hi = mid-1; } re(ans,fu(i,hi).second); } 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...