이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }
const int MOD = 1e9 + 7;
const int MX = 5e5 + 10;
const ll INF = 1e18;
struct frac {
ll n, d; frac(ll _n, ll _d) { n = _n; d = _d; if (d < 0) n *= -1, d *= -1; }
frac(ll _n) : frac(_n,1) {} frac() : frac(0) {}
friend frac abs(frac F) { return frac(abs(F.n), F.d); }
frac operator-() const { return frac(-n, d); }
friend bool operator<(const frac& l, const frac& r) {
if (l.n < 0 && r.n >= 0) return true; if (l.n < 0 && r.n < 0) return -r < -l;
return l.n / l.d == r.n / r.d ? (l.n % l.d) * r.d < (r.n % r.d) * l.d : l.n / l.d < r.n / r.d;
}
friend bool operator>(const frac& l, const frac& r) { return r < l; }
friend bool operator==(const frac& l, const frac& r) { return l.n == r.n && l.d == r.d; }
friend bool operator!=(const frac& l, const frac& r) { return !(l == r); }
friend bool operator<=(const frac& l, const frac& r) { return l < r || l == r; }
friend bool operator>=(const frac& l, const frac& r) { return l > r || l == r; }
friend frac operator+(const frac& l, const frac& r) { return frac(l.n * r.d + r.n * l.d, l.d * r.d); }
friend frac operator-(const frac& l, const frac& r) { return frac(l.n * r.d - r.n * l.d, l.d * r.d); }
friend frac operator*(const frac& l, const frac& r) { return frac(l.n * r.n, l.d * r.d); }
friend frac operator*(const frac& l, int r) { return l * frac(r, 1); }
friend frac operator*(int r, const frac& l) { return l * r; }
friend frac operator/(const frac& l, const frac& r) { return l * frac(r.d, r.n); }
friend frac operator/(const frac& l, const int& r) { return l / frac(r, 1); }
friend frac operator/(const int& l, const frac& r) { return frac(l, 1) / r; }
friend frac& operator+=(frac& l, const frac& r) { return l = l + r; }
friend frac& operator-=(frac& l, const frac& r) { return l = l - r; }
template<class T> friend frac& operator*=(frac& l, const T& r) { return l = l * r; }
template<class T> friend frac& operator/=(frac& l, const T& r) { return l = l / r; }
};
int N; ll W; int S[MX], Q[MX]; vi A; priority_queue<pi> PQ; ll tot = 0;
pair<int, pair<frac, int>> ans;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N >> W; FOR(i, 1, N + 1) cin >> S[i] >> Q[i];
A.rsz(N); iota(all(A), 1); sort(all(A), [&](int a, int b) { return frac(S[a], Q[a]) < frac(S[b], Q[b]); });
EACH(C, A) {
PQ.push({Q[C], C}); tot += Q[C];
while (tot * frac(S[C], Q[C]) > W) {
tot -= PQ.top().f; PQ.pop();
}
ckmax(ans, {sz(PQ), {-tot * frac(S[C], Q[C]), C}});
}
while (!PQ.empty()) PQ.pop(); tot = 0;
if (ans.f == 0) { cout << "0" << "\n"; return 0; }
EACH(C, A) {
PQ.push({Q[C], C}); tot += Q[C];
while (tot * frac(S[C], Q[C]) > W) {
tot -= PQ.top().f; PQ.pop();
}
if (C == ans.s.s) {
cout << sz(PQ) << "\n";
while (!PQ.empty()) {
cout << PQ.top().s << "\n";
PQ.pop();
}
break;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'bool operator<(const frac&, const frac&)':
hiring.cpp:68:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
68 | if (l.n < 0 && r.n >= 0) return true; if (l.n < 0 && r.n < 0) return -r < -l;
| ^~
hiring.cpp:68:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
68 | if (l.n < 0 && r.n >= 0) return true; if (l.n < 0 && r.n < 0) return -r < -l;
| ^~
hiring.cpp: In function 'int main()':
hiring.cpp:114:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
114 | while (!PQ.empty()) PQ.pop(); tot = 0;
| ^~~~~
hiring.cpp:114:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
114 | while (!PQ.empty()) PQ.pop(); tot = 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... |