This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 10, M = 2e4 + 10;
int n;
long long w;
int s[N], q[N];
pair<long long, int> st[4 * M];
void update(int index, int l, int r, int x) {
if(l > r || r < x || x < l) return;
if(l == r) {
st[index].first += x;
st[index].second += 1;
return;
}
int mid = (l + r) / 2;
update(2 * index + 1, l, mid, x);
update(2 * index + 2, mid + 1, r, x);
st[index].first = st[2 * index + 1].first + st[2 * index + 2].first;
st[index].second = st[2 * index + 1].second + st[2 * index + 2].second;
}
pair<long long, int> get(int index, int l, int r, int L, int R) {
if(l > r || r < L || R < l) return {0, 0};
if(L <= l && r <= R) return st[index];
int mid = (l + r) / 2;
pair<long long, int> p1 = get(2 * index + 1, l, mid, L, R);
pair<long long, int> p2 = get(2 * index + 2, mid + 1, r, L, R);
return {p1.first + p2.first, p1.second + p2.second};
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
for(int i = 0; i < 4 * M; i++) st[i].first = st[i].second = 0;
cin >> n >> w;
for(int i = 0; i < n; i++) cin >> s[i] >> q[i];
int order[n];
iota(order, order + n, 0);
sort(order, order + n, [&](int i, int j) { return 1.0 * s[i] * q[j] < 1.0 * s[j] * q[i]; });
double res = 1e18;
int cnt = 0, index = 0;
for(int i = 0; i < n; i++) {
int l = 0, r = M - 1;
int ans = l;
while(l <= r) {
int mid = (l + r) / 2;
pair<long long, int> sum = get(0, 0, M - 1, 0, mid);
if(sum.first * 1.0 * s[order[i]] / q[order[i]] + s[order[i]] <= w) {
ans = mid;
l = mid + 1;
} else r = mid - 1;
}
pair<long long, int> sum = get(0, 0, M - 1, 0, ans);
if(cnt == sum.second) {
if(res > sum.first * 1.0 * s[order[i]] / q[order[i]] + s[order[i]]) {
res = sum.first * 1.0 * s[order[i]] / q[order[i]] + s[order[i]];
index = i;
}
} else if(cnt < sum.second) {
cnt = sum.second;
res = sum.first * 1.0 * s[order[i]] / q[order[i]] + s[order[i]];
index = i;
}
update(0, 0, M - 1, q[order[i]]);
}
vector<int> jebala_vas_konstrukcija;
jebala_vas_konstrukcija.push_back(order[index]);
vector<pair<int, int>> smarate;
for(int i = 0; i < index; i++) smarate.push_back({q[order[i]], order[i]});
sort(smarate.begin(), smarate.end());
for(int i = 0; i < cnt; i++) jebala_vas_konstrukcija.push_back(smarate[i].second);
sort(jebala_vas_konstrukcija.begin(), jebala_vas_konstrukcija.end());
cout << jebala_vas_konstrukcija.size() << "\n";
for(int i : jebala_vas_konstrukcija) cout << i + 1 << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |