Submission #446419

#TimeUsernameProblemLanguageResultExecution timeMemory
446419JerryLiu06Hiring (IOI09_hiring)C++17
94 / 100
469 ms13336 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() #define bg(x) begin(x) #define all(x) bg(x), end(x) #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define R0F(i, a) ROF(i, 0, a) #define EACH(a, x) for (auto& a : x) ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); } const int MOD = 1e9 + 7; const int MX = 5e5 + 10; const ll INF = 1e18; struct frac { ll n, d; frac(ll _n, ll _d) { n = _n, d = _d; if (d < 0) n *= -1, d *= -1; } frac(ll _n) : frac(_n,1) {} frac() : frac(0) {} friend frac abs(frac F) { return frac(abs(F.n), F.d); } friend bool operator<(const frac& l, const frac& r) { return l.n * r.d < r.n * l.d; } friend bool operator>(const frac& l, const frac& r) { return l.n * r.d > r.n * l.d; } friend bool operator<=(const frac& l, const frac& r) { return l.n * r.d <= r.n * l.d; } friend bool operator>=(const frac& l, const frac& r) { return l.n * r.d >= r.n * l.d; } friend bool operator==(const frac& l, const frac& r) { return l.n == r.n && l.d == r.d; } friend bool operator!=(const frac& l, const frac& r) { return !(l == r); } frac operator-() const { return frac(-n, d); } friend frac operator+(const frac& l, const frac& r) { return frac(l.n * r.d + r.n * l.d, l.d * r.d); } friend frac operator-(const frac& l, const frac& r) { return frac(l.n * r.d - r.n * l.d, l.d * r.d); } friend frac operator*(const frac& l, const frac& r) { return frac(l.n * r.n, l.d * r.d); } friend frac operator*(const frac& l, int r) { return l * frac(r, 1); } friend frac operator*(int r, const frac& l) { return l * r; } friend frac operator/(const frac& l, const frac& r) { return l * frac(r.d, r.n); } friend frac operator/(const frac& l, const int& r) { return l / frac(r, 1); } friend frac operator/(const int& l, const frac& r) { return frac(l, 1) / r; } friend frac& operator+=(frac& l, const frac& r) { return l = l + r; } friend frac& operator-=(frac& l, const frac& r) { return l = l - r; } template<class T> friend frac& operator*=(frac& l, const T& r) { return l = l * r; } template<class T> friend frac& operator/=(frac& l, const T& r) { return l = l / r; } }; int N; ll W; int S[MX], Q[MX]; vi A; priority_queue<pi> PQ; int tot; pair<int, pair<frac, int>> ans; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> W; FOR(i, 1, N + 1) cin >> S[i] >> Q[i]; A.rsz(N); iota(all(A), 1); sort(all(A), [&](int a, int b) { return frac(S[a], Q[a]) < frac(S[b], Q[b]); }); ans = {0, {-MOD, 0}}; EACH(C, A) { PQ.push({Q[C], C}); tot += Q[C]; while (tot * frac(S[C], Q[C]) > W) { tot -= PQ.top().f; PQ.pop(); } ckmax(ans, {sz(PQ), {-tot * frac(S[C], Q[C]), C}}); } while (!PQ.empty()) PQ.pop(); int tot = 0; if (ans.f == 0) { cout << "0" << "\n"; return 0; } EACH(C, A) { PQ.push({Q[C], C}); tot += Q[C]; while (tot * frac(S[C], Q[C]) > W) { tot -= PQ.top().f; PQ.pop(); } if (C == ans.s.s) { cout << sz(PQ) << "\n"; while (!PQ.empty()) { cout << PQ.top().s << "\n"; PQ.pop(); } break; } } }

Compilation message (stderr)

hiring.cpp: In function 'int main()':
hiring.cpp:112:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
  112 |     while (!PQ.empty()) PQ.pop(); int tot = 0;
      |     ^~~~~
hiring.cpp:112:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  112 |     while (!PQ.empty()) PQ.pop(); int tot = 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...