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;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
struct node {
int cnt = 0; ld val = 0;
};
const int len = 32768;
const ld eps = 1e-50;
vector<node> st(len * 2);
void add(int idx, ld val, int i = 1, int s = 0, int e = len){
if(idx >= e || idx < s) return;
if(idx == s && s + 1 == e) {
st[i].val += val;
st[i].cnt++;
return;
}
add(idx, val, i * 2, s, (s + e) / 2);
add(idx, val, i * 2 + 1, (s + e) / 2, e);
st[i].val = st[i * 2].val + st[i * 2 + 1].val;
st[i].cnt = st[i * 2].cnt + st[i * 2 + 1].cnt;
}
pair<int, ld> walk(ld b, ld m, int i = 1) {
if(i >= len){
if(st[i].cnt == 0) return {0, b};
if(st[i].val < eps) return {st[i].cnt, b};
ld val = st[i].val / st[i].cnt * m;
return {(int)(floor(b / val) + 0.5), b - floor(b / val) * val};
}
if(b - st[i * 2].val * m > -eps){
pair<int, int> r = walk(b - st[i * 2].val * m, m, i * 2 + 1);
return {st[i * 2].cnt + r.first, r.second};
}
else return walk(b, m, i * 2);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; ld b; cin >> n >> b;
vector<pair<pair<ld, int>, int>> v;
for (int i = 0; i < n; i++) {
int c, q; cin >> c >> q;
v.push_back({{(ld)c / (ld)q, q}, i});
}
sort(all(v));
pair<int, int> mx = {0, 0}; int mxi;
for (int i = 0; i < n; i++) {
auto& [x, q] = v[i].first;
add(q, q);
pair<int, int> ret = walk(b, x);
if(ret > mx){
mx = ret;
mxi = i;
}
}
set<pair<int, int>> s;
vector<int> res;
for (int i = 0; i <= mxi; i++) {
int q = v[i].first.second, j = v[i].second;
s.insert({q, j});
}
int j = 0;
for (auto &i : s) {
if(j >= mx.first) break;
res.push_back(i.second);
j++;
}
cout << mx.first << "\n";
for (auto &i : res) {
cout << i + 1 << "\n";
}
}
Compilation message (stderr)
hiring.cpp: In function 'int main()':
hiring.cpp:71:23: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
71 | for (int i = 0; i <= mxi; i++) {
| ~~^~~~~~
# | 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... |