Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int const maxn = 1e5;
- long long const mod = 1000000007;
- int n, k;
- double ttt = 0.0;
- vector<double> a, b;
- vector<int> current, order;
- void input() {
- cin >> n >> k;
- double temp;
- for (int i = 0; i < n; i++) {
- cin >> temp;
- a.push_back(temp);
- cin >> temp;
- b.push_back(temp);
- current.push_back(i);
- }
- for (int i = 0; i < k; i++) {
- order.push_back(0);
- }
- }
- inline bool cmp(const int &f1, const int &f2) {
- return ((ttt * b[f1] + a[f1]) / (b[f1]) > (ttt * b[f2] + a[f2]) / (b[f2]));
- }
- inline bool possible() {
- sort(current.begin(), current.end(), cmp);
- double up = 0.0, down = 0.0;
- for (int i = 0; i < k; i++) {
- up += a[current[i]];
- down += b[current[i]];
- }
- if (ttt <= up / down) {
- for (int i = 0; i < k; i++) {
- order[i] = current[i] + 1;
- }
- return true;
- } else {
- return false;
- }
- }
- void solve() {
- double l = 0.0, r = 10000000.0;
- while (r - l > 0.000001) {
- ttt = (l + r) / 2.0;
- if (possible()) {
- l = ttt;
- } else {
- r = ttt;
- }
- }
- for (int i = 0; i < k; i++) {
- cout << order[i] << " ";
- }
- }
- int32_t main() {
- freopen("kbest.in", "r", stdin);
- freopen("kbest.out", "w", stdout);
- IOS
- input();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement