QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#257053 | #7750. Revenge on My Boss | ucup-team1055 | RE | 0ms | 3784kb | C++20 | 2.9kb | 2023-11-18 23:48:51 | 2023-11-18 23:48:52 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = int(s); i < int(n); i++)
#define rrep(i, s, n) for (int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i128 = __int128_t;
template <class T> bool chmin(T &a, T b) {
if (a <= b) return false;
a = b;
return true;
}
template <class T> bool chmax(T &a, T b) {
if (a >= b) return false;
a = b;
return true;
}
void solve() {
int n;
std::cin >> n;
std::vector<ll> a(n), b(n), c(n);
ll sum_a = 0;
std::vector<int> neg, pos, zero;
rep(i, 0, n) {
std::cin >> a[i] >> b[i] >> c[i];
sum_a += a[i];
if (b[i] - a[i] < 0) {
neg.emplace_back(i);
} else if (b[i] - a[i] == 0) {
zero.emplace_back(i);
} else {
pos.emplace_back(i);
}
}
auto check = [&](ll x) -> std::vector<int> {
std::vector<int> p;
ll sum = 0;
std::sort(all(neg), [&](int i, int j) -> bool {
ll lhs = x - (sum_a * c[i] + b[i] * c[i]);
ll rhs = x - (sum_a * c[j] + b[j] * c[j]);
return i128(lhs) * c[j] > i128(rhs) * c[i];
});
for (auto i : neg) {
if (sum * c[i] + sum_a * c[i] + b[i] * c[i] > x) {
return {};
}
sum += b[i] - a[i];
p.emplace_back(i);
}
for (auto i : zero) {
if (sum * c[i] + sum_a * c[i] + b[i] * c[i] > x) {
return {};
}
sum += b[i] - a[i];
p.emplace_back(i);
}
using P = std::pair<ll, int>;
std::priority_queue<P> pq;
std::queue<int> que;
std::sort(all(pos), [&](int i, int j) -> bool {
ll lhs = x - (sum_a * c[i] + b[i] * c[i]);
ll rhs = x - (sum_a * c[j] + b[j] * c[j]);
return i128(lhs) * c[j] > i128(rhs) * c[i];
});
for (auto i : pos) {
sum += b[i] - a[i];
}
for(auto i: pos) {
sum -= b[i] - a[i];
assert(sum * c[i] + sum_a * c[i] + b[i] * c[i] <= x);
}
if(!pq.empty()) {
return {};
}
std::reverse(all(p));
auto ans = pos;
ans.insert(ans.end(), all(p));
return ans;
};
ll ok = 2'000'000'000'000'000'000;
ll ng = 0;
while ((ok - ng) > 1) {
ll mid = (ok + ng) >> 1;
auto ret = check(mid);
if (ret.empty()) {
ng = mid;
} else {
ok = mid;
}
}
auto ans = check(ok);
rep(i, 0, n) {
std::cout << ans[i] + 1 << " \n"[i == n - 1];
}
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
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 1 2 4 3 4 8 2 5 9 7 1 6
result:
ok correct
Test #2:
score: -100
Runtime Error
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...