제출 #405608

#제출 시각아이디문제언어결과실행 시간메모리
405608Aldas25Hiring (IOI09_hiring)C++14
94 / 100
1599 ms19948 KiB
#pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define pb push_back #define f first #define s second typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<piii> viii; const int MAXN = 500100, MAXK = 30; const ll MOD = 998244353; const int INF = 1e9; const ld PI = asin(1) * 2; bool cmp (pair<pair<ll, ll>, int> a, pair<pair<ll, ll>, int> b) { return a.f.f * b.f.s < a.f.s * b.f.f; } int n; ll w; vector<pair<pair<ll, ll>, int>> seq; pair<ll, ll> mn; pair<ll, ll> check (int k, bool print=false) { //cout << " checking k = " << k << endl; priority_queue<pair<ll, int>> qu; pair<ll, ll> curCost = {0, 1}; ll curSum = 0; pair<ll, ll> ret = {-1, -1}; for (auto p : seq) { ll s = p.f.f, q = p.f.s; int id = p.s; curCost = {s, q}; pair<ll, int> tp = {-1, -1}; if ((int)qu.size() == k) { tp = qu.top(); qu.pop(); curSum -= tp.f; } if (tp.f == -1 || tp.f > q) tp = {q, id}; qu.push(tp); curSum += tp.f; if ((int)qu.size() == k) { //if (curSum * curCost.f <= w * curCost.s) { /* if (print) { while (!qu.empty()) { auto tpp = qu.top(); cout << tpp.s << "\n"; qu.pop(); } } */ //return true; // } if (curSum * curCost.f * ret.s <= ret.f * curCost.s) { ret = {curSum*curCost.f, curCost.s}; } if (print && ret.f * mn.s == ret.s * mn.f) { while (!qu.empty()) { auto tpp = qu.top(); cout << tpp.s << "\n"; qu.pop(); } return ret; } } } return ret; } int main() { FAST_IO; cin >> n >> w; FOR(i, 1, n) { ll s, q; cin >> s >> q; seq.pb({{s, q}, i}); } sort(seq.begin(), seq.end(), cmp); int le = 0, ri = n; while (le < ri) { int mid = (le+ri+1)/2; auto p = check(mid); if (p.f != -1 && p.f <= w*p.s) le = mid; else ri = mid-1; } cout << le << "\n"; if (le > 0) { mn = check(le); check (le, true); } 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...