Submission #536247

#TimeUsernameProblemLanguageResultExecution timeMemory
536247lovrotHiring (IOI09_hiring)C++11
84 / 100
612 ms65536 KiB
#include <bits/stdc++.h> #include <unistd.h> #define X first #define Y second #define ll long long #define pii pair<int, int> #define pb push_back #define vec vector #define siz size() #define pri(i, poc, n, pov) for(int i = (int) poc; i < (int) n; i += (int) pov) #define od(i, poc, n, pov) for(int i = (int) poc; i > (int) n; i -= (int) pov) using namespace std; const double INF = 1e18; const int LOG = 19; const int OFF = (1 << LOG); struct skup{ long double sum = 0; int n = 0; } tour[OFF * 2]; skup zero; int n, tourpos[OFF]; bool out[OFF]; long double s[OFF], q[OFF], w; vec<pair<long double, int>> q_v, v, q_out; skup merge(skup a, skup b){ skup ret; ret.sum = a.sum + b.sum; ret.n = a.n + b.n; return ret; } void update(int x, long double v){ x += OFF; tour[x].sum = v; tour[x].n = 1; x >>= 1; while(x){ tour[x] = merge(tour[x * 2], tour[x * 2 + 1]); x >>= 1; } } skup query(int v, int lo = 0, int hi = OFF, int x = 1){ if(tour[x].sum <= v) return tour[x]; if(x >= OFF) return zero; int mi = (lo + hi) / 2; if(tour[x * 2].sum >= v) return query(v, lo, mi, x * 2); return merge(tour[x * 2], query(v - tour[x * 2].sum, mi, hi, x * 2 + 1)); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); setprecision(9); cin >> n >> w; pri(i, 0, n, 1){ cin >> s[i] >> q[i]; v.pb({s[i] / q[i], i}); q_v.pb({q[i], i}); } sort(v.begin(), v.end()); sort(q_v.begin(), q_v.end()); pri(i, 0, n, 1){ tourpos[q_v[i].Y] = i; } int mx = -1, mxi; long double mnw = w; pri(i, 0, n, 1){ int x = v[i].Y; long double t = v[i].X; long double zb = w / t; long double qq = zb - q[x]; skup res = query(qq); res.n++; res.sum += q[x]; if(res.n >= mx){ if(res.n == 2){ //cout << x << " " << t * res.sum << "\n"; } if(mx == res.n && mnw > t * res.sum){ mxi = x; mnw = t * res.sum; } if(res.n > mx){ mx = res.n; mxi = x; mnw = t * res.sum; } } update(tourpos[x], q[x]); } long double zb = q[mxi]; long double t = s[mxi] / q[mxi]; cout << mx << "\n"; out[mxi] = true; pri(i, 0, n, 1){ if(mxi == v[i].Y) break; q_out.pb({q[v[i].Y], v[i].Y}); } sort(q_out.begin(), q_out.end()); for(pair<long double, int> i : q_out){ if(t * (i.X + zb) > w) break; out[i.Y] = true; zb += i.X; } pri(i, 0, n, 1){ if(out[i]) cout << i + 1 << "\n"; } return 0; }

Compilation message (stderr)

hiring.cpp: In function 'int main()':
hiring.cpp:115:14: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
  115 |  long double zb = q[mxi];
      |              ^~
#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...