제출 #212422

#제출 시각아이디문제언어결과실행 시간메모리
212422mode149256Hiring (IOI09_hiring)C++14
94 / 100
542 ms53476 KiB
/*input 5 37819 19739 14341 8878 7344 6477 7829 8200 9300 13623 13623 */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const int MOD = 1000000007; const ll INF = std::numeric_limits<ll>::max(); const int MX = 100101; const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } struct ppl { ll S, Q; int i; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; ll W; cin >> N >> W; vector<ppl> sk(N); for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; sk[i] = {a, b, i + 1}; } sort(sk.rbegin(), sk.rend(), [&](const ppl & a, const ppl & b) { return a.Q * b.S < b.Q * a.S; }); int kiek = 0; int l = 1; ll sumokejau = MOD; multiset<ll> buvo; ll sumQ = 0; if (sk[0].Q <= W) { kiek = 1; l = 0; sumokejau = sk[0].Q; } buvo.insert(sk[0].Q); // it first not included [0; it-1] it auto it = buvo.begin(); int j = 0; // for (auto u : sk) // printf("%d %lld %lld\n", u.i, u.S, u.Q); // printf("\n"); for (int i = 1; i < N; ++i) { sumQ += sk[i].Q; while (j and sumQ * sk[i].S > W * sk[i].Q) { j--; it--; sumQ -= *it; } if (j + 1 <= i and (sumQ + *it) * sk[i].S <= W * sk[i].Q) { sumQ += *it; it++; j++; } if (sumQ * sk[i].S <= W * sk[i].Q) { if (j + 1 > kiek or (j + 1 == kiek and sumQ * sk[i].S * sk[l].Q < sumokejau * sk[i].Q)) { kiek = j + 1; l = i; sumokejau = sumQ * sk[i].S; } } // printf("i = %d, sumQ = %d, kiek = %d\n", i, sumQ, j + 1); buvo.insert(sk[i].Q); sumQ -= sk[i].Q; if (it == buvo.end() or sk[i].Q < *it) { sumQ += sk[i].Q; j++; } } vector<ppl> ans; for (int i = 0; i < l; ++i) ans.push_back(sk[i]); sort(ans.begin(), ans.end(), [&](const ppl a, const ppl b) { return a.Q < b.Q; }); printf("%d\n", kiek); printf("%d\n", sk[l].i); for (int i = 0; i < kiek - 1; ++i) printf("%d\n", ans[i].i); // printf("l = %d, id = %d\n", l, sk[l].i); } /* Look for: * special cases (n=1?) * overflow (ll vs int?) * the exact constraints (multiple sets are too slow for n=10^6 :( ) * array bounds */
#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...