제출 #520654

#제출 시각아이디문제언어결과실행 시간메모리
520654tkwiatkowskiHiring (IOI09_hiring)C++17
62 / 100
216 ms25236 KiB
/* Zadanie: Hiring Autor: Tomasz Kwiatkowski */ #include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; const int MAXN = 1e6 + 7; const int INF = 1e9 + 7; struct frac { long long p, q; frac () {} frac (long long a, long long b = 1) : p(a), q(b) {} bool operator==(frac x) { return p*x.q == q*x.p; } bool operator<=(frac x) { return p*x.q <= q*x.p; } bool operator<(frac x) { return p*x.q < q*x.p; } frac operator*(long long x) { return frac(p*x, q); } }; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; long long w; cin >> n >> w; vector<pair<frac, int>> sorted(n); int i = 0; for (auto& [x, ind] : sorted) { cin >> x.p >> x.q; ind = i++; } vector<pair<frac, int>> candidates(sorted); sort(sorted.begin(), sorted.end(), [](auto lhs, auto rhs) { if (lhs.fi == rhs.fi) { if (lhs.fi.q == rhs.fi.q) return lhs.se < lhs.se; return lhs.fi.q < rhs.fi.q; } return rhs.fi < lhs.fi; }); sort(candidates.begin(), candidates.end(), [](auto lhs, auto rhs) { if (lhs.fi.q == rhs.fi.q) return lhs.se < lhs.se; return lhs.fi.q < rhs.fi.q; }); vector<bool> ok(n, true); int j = 0; int cnt = 0; frac money(w); int k = 0; long long sum_q = 0; for (auto [x, ind] : sorted) { if (ok[ind]) ++cnt, sum_q += x.q; ok[ind] = false; while (j < n && (x*(sum_q + candidates[j].fi.q*ok[candidates[j].se]) <= frac(w))) { sum_q += candidates[j].fi.q*ok[candidates[j].se]; cnt += ok[candidates[j].se]; if (cnt > k) k = cnt, money = x*sum_q; else if (cnt == k && (x*sum_q < money)) money = x*sum_q; ok[candidates[j].se] = false; ++j; } sum_q -= x.q; --cnt; } cout << k << '\n'; ok = vector<bool>(n, true); vector<bool> chosen(n, false); j = 0; cnt = 0; sum_q = 0; for (auto [x, ind] : sorted) { if (ok[ind]) ++cnt, sum_q += x.q; ok[ind] = false; chosen[ind] = true; while (j < n && (x*(sum_q + candidates[j].fi.q*ok[candidates[j].se]) <= frac(w))) { chosen[candidates[j].se] = true; sum_q += candidates[j].fi.q*ok[candidates[j].se]; cnt += ok[candidates[j].se]; if (cnt == k && (x*sum_q == money)) { for (int i = 0; i < n; ++i) if (chosen[i]) cout << i + 1 << '\n'; return 0; } ok[candidates[j].se] = false; ++j; } sum_q -= x.q; chosen[ind] = false; --cnt; } return 0; }
#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...