QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#256305 | #7750. Revenge on My Boss | ucup-team1631 | WA | 1111ms | 11728kb | C++23 | 3.5kb | 2023-11-18 18:26:31 | 2023-11-18 18:26:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
return a > b ? (a = b, 1) : 0;
}
using P = pair<ll, int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < (int)v.size(); ++i) {
os << v[i];
if (i < (int)v.size() - 1) os << " ";
}
return os;
}
template <typename T, typename U, typename V>
ostream& operator<<(ostream& os, const tuple<T, U, V>& p) {
auto [x, y, z] = p;
os << "(" << x << ", " << y << ", " << z << ")";
return os;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<tuple<ll, ll, int>> neg, pos;
vector<ll> as(n), bs(n), cs(n);
rep(i, 0, n) {
int a, b, c;
cin >> a >> b >> c;
if (a < b) {
neg.push_back({b - a, c, i});
} else {
pos.push_back({a - b, c, i});
}
as[i] = a, bs[i] = b, cs[i] = c;
}
auto calc = [&](auto& val, ll X, ll offset) -> vector<int> {
vector<tuple<ll, ll, int>> items;
for (auto [x, c, i] : val) {
items.push_back({X / c - bs[i] - offset, x, i});
}
sort(all(items));
ll deadline = 1e18;
priority_queue<P, vector<P>> pq;
vector<int> idx;
rep(_, 0, val.size()) {
while (!items.empty() && deadline <= get<0>(items.back())) {
auto [_, x, i] = items.back();
items.pop_back();
pq.push({x, i});
}
if (pq.empty()) {
deadline = get<0>(items.back());
while (!items.empty() && deadline <= get<0>(items.back())) {
auto [_, x, i] = items.back();
items.pop_back();
pq.push({x, i});
}
}
auto [x, i] = pq.top();
pq.pop();
idx.push_back(i);
deadline -= x;
if (deadline < 0) return {};
}
return idx;
};
auto binsearch = [&](auto& val, ll offset) {
ll lb = 0, ub = 1e18;
while (ub - lb > 1) {
ll X = (lb + ub) / 2;
auto res = calc(val, X, offset);
if (res.empty())
lb = X;
else
ub = X;
}
return calc(val, ub, offset);
};
ll s = 0;
for (auto [x, c, i] : neg) s += as[i];
for (auto [x, c, i] : pos) s += bs[i];
auto negidx = binsearch(neg, s);
auto posidx = binsearch(pos, s);
reverse(all(posidx));
vector<int> ans;
for (int i : negidx) ans.push_back(i);
for (int i : posidx) ans.push_back(i);
rep(i, 0, n) cout << ans[i] + 1 << (i < n - 1 ? " " : "\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
2 4 1 1 4 5 1 5 1 9 1 9 8 1 9 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 8 3 2 7
output:
3 2 1 4 3 4 8 2 5 9 7 1 6
result:
ok correct
Test #2:
score: -100
Wrong Answer
time: 1111ms
memory: 11728kb
input:
1 100000 581297 102863 1 742857 42686 1 676710 233271 1 443055 491162 1 442056 28240 1 769277 331752 1 8608 369730 1 495112 525554 1 787449 938154 1 441186 850694 1 84267 925450 1 740811 32385 1 834021 37680 1 257878 564126 1 90618 914340 1 239641 463103 1 40687 343062 1 587737 458554 1 103684 48666...
output:
32063 35138 37175 93403 65092 93220 18942 61401 90655 62028 77582 77581 82112 72163 18220 43645 30468 80107 54173 17444 14872 8630 50133 26305 35 70096 40298 10072 56385 75312 79444 19284 81622 95793 96892 82320 8443 11434 56765 72103 89089 86041 48305 32033 88191 83243 9383 66880 81866 31386 23642 ...
result:
wrong answer Wrong Answer on Case#1