Submission #733755

#TimeUsernameProblemLanguageResultExecution timeMemory
733755penguin133Hiring (IOI09_hiring)C++17
49 / 100
609 ms21128 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, w; pii A[500005]; bool cmp(pii a, pii b){ return ((long double)a.fi / (long double)a.se.fi) < ((long double)b.fi / (long double)b.se.fi); } struct node{ int s, e, m, val, val2; node *l, *r; node(int _s, int _e){ s = _s, e = _e, m = (s + e) >> 1; if(s != e)l = new node(s, m), r = new node(m+1, e); val = val2 = 0; } void upd(int p){ if(s == e)val += s, val2++; else{ if(p <= m)l->upd(p); else r->upd(p); val = l->val + r->val; val2 = l->val2 + r->val2; } } pi qry(int a, int b){ if(s == a && e == b)return {val,val2}; else if(b <= m)return l->qry(a, b); else if(a > m)return r->qry(a, b); else { pi lft = l->qry(a, m), rgt = r->qry(m+1, b); return {lft.fi + rgt.fi, lft.se + rgt.se}; } } }*root; void solve(){ cin >> n >> w; int mx = 0; for(int i=1;i<=n;i++)cin >> A[i].fi >> A[i].se.fi, A[i].se.se = i, mx = max(mx, A[i].se.fi); root = new node(1, mx); sort(A+1, A+n+1, cmp); vector <pi> v; //pair<int, long double> ans = {0, 0.0L}; vector <int> fin; int ans2 = 0; for(int i=1;i<=n;i++){ int x = w * A[i].se.fi / A[i].fi; x -= A[i].se.fi; /* vector <int> tmp = {A[i].se.se}; for(auto [j, k] : v){ if(x >= j)x -= j, tmp.push_back(k); } v.push_back({A[i].se.fi, A[i].se.se}); sort(v.begin(), v.end()); int used = w * A[i].se.fi / A[i].fi - x; long double brub = (long double)(used * A[i].fi) / A[i].se.fi; if((int)tmp.size() > ans.fi || ((int)tmp.size() == ans.fi && ans.se < -brub))ans = {(int)tmp.size(), -brub}, fin = tmp; */ int lo = 1, hi = mx, ans = mx + 1, val = 0; while(lo <= hi){ int mid = (lo + hi) >> 1; pi res = root->qry(1, mid); if(res.fi >= x)ans = mid, hi = mid - 1; else lo = mid + 1; } if(ans != 1)val = root->qry(1, ans - 1).se; if(ans != mx + 1){ int left = root->qry(ans, ans).se; x -= root->qry(1, ans - 1).fi; val += min(x/ans, left); } val++; ans2 = max(ans2, val); root->upd(A[i].se.fi); } /* cout << fin.size() << '\n'; for(auto i : fin)cout << i << '\n'; */ cout << ans2 << '\n'; for(int i=1;i<=ans2;i++)cout << i << '\n'; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

Compilation message (stderr)

hiring.cpp:100:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  100 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...