이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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;
}
int walk(ld b, ld m, int i = 1){
if(i >= len){
if(st[i].val * m <= b) return st[i].cnt;
else return 0;
}
if(st[i * 2].val * m <= b) return st[i * 2].cnt + walk(b - st[i * 2].val * m, m, i * 2 + 1);
else return walk(b, m, i * 2);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, b; cin >> n >> b;
vector<pair<ld, int>> v;
for (int i = 0; i < n; i++) {
int c, q; cin >> c >> q;
v.push_back({(ld)c / (ld)q, q});
}
sort(all(v));
int mx = 0, mxi;
for (int i = 0; i < n; i++) {
auto& [x, q] = v[i];
add(q, q);
int ret = walk(b, x);
if(ret > mx){
mx = ret;
mxi = i;
}
}
cout << mx << "\n";
for (int i = 0; i < mx; i++)
cout << 0 << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'int main()':
hiring.cpp:52:17: warning: variable 'mxi' set but not used [-Wunused-but-set-variable]
52 | int mx = 0, mxi;
| ^~~
# | 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... |