제출 #393857

#제출 시각아이디문제언어결과실행 시간메모리
393857BertedHiring (IOI09_hiring)C++14
36 / 100
165 ms12100 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cassert> #define ll long long #define pii pair<ll, ll> #define ppi pair<pii, int> #define fst first #define snd second using namespace std; const int SZ = (1 << 15), MX = 1000000; int N, cnt[MX + 1]; ll K; ppi A[500001]; inline bool comp(const ppi &L, const ppi &R) {return L.fst.fst * R.fst.snd < L.fst.snd * R.fst.fst;} int main() { //freopen("hiring.in", "r", stdin); ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i].fst.fst >> A[i].fst.snd; assert(A[i].fst.fst <= MX); assert(A[i].fst.snd <= MX); A[i].snd = i; } sort(A, A + N, comp); int j = 0, c = 0, best = -1, bestIdx = -1; pii bestFrac = {-1, 1}; ll S = 0; for (int i = 0; i < N; i++) { cnt[A[i].fst.snd]++; if (A[i].fst.snd <= j) {S += A[i].fst.snd; c++;} //cerr << S << "\n"; for (; j < MX && (S + (ll)(j + 1) * cnt[j + 1]) * A[i].fst.fst <= A[i].fst.snd * K; j++) { S += (ll)(j + 1) * cnt[j + 1]; c += cnt[j + 1]; } for (; j && S * A[i].fst.fst > A[i].fst.snd * K; j--) { S -= (ll)j * cnt[j]; c -= cnt[j]; } //cerr << i << ": " << A[i].fst.fst << " " << A[i].fst.snd << " " << j << "\n"; int tp = (A[i].fst.snd * K - A[i].fst.fst * S) / (A[i].fst.fst * (ll)(j + 1)), t = c + tp; pii f = {(A[i].fst.snd * K - A[i].fst.fst * (S + tp * (j + 1))), A[i].fst.snd}; if ((t > best) || (t == best && f.fst * bestFrac.snd > f.snd * bestFrac.fst)) {best = t; bestFrac = f; bestIdx = i;} } pii frac = A[bestIdx].fst; for (int i = 0; i <= bestIdx; i++) {A[i].fst.fst = A[i].fst.snd; A[i].fst.snd = A[i].snd;} sort(A, A + bestIdx + 1); S = 0; vector<int> ans; for (int i = 0; i <= bestIdx; i++) { S += A[i].fst.fst; if (K * frac.snd < frac.fst * S) {break;} else {ans.push_back(A[i].snd + 1);} } //cerr << "Best: " << best << "\n"; //assert(best <= (int)ans.size()); cout << best << "\n"; for (const int &x : ans) cout << x << "\n"; 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...