QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#254653 | #7750. Revenge on My Boss | ucup-team027# | WA | 1ms | 3392kb | C++23 | 1.6kb | 2023-11-18 13:31:21 | 2023-11-18 13:31:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
#define int long long
bool ok(int mid, int n, vector<tuple<int, int, int>> &A, vector<int> &perm) {
vector<tuple<int, int, int>> pos, neg;
for (int i = 0; i < n; i++) {
auto [a, b, c] = A[i];
int mx = mid/c - a;
int dif = a-b;
if (dif <= 0) {
neg.emplace_back(-mx, dif, i);
} else {
pos.emplace_back(-dif, mx, i);
}
}
sort(neg.begin(), neg.end());
sort(pos.begin(), pos.end());
int cursum = 0;
for (auto [a, b, c]: A) {
cursum += b;
}
vector<int> pp;
for (auto [mx, dif, i]: neg) {
if (cursum > -mx) return 0;
cursum += dif;
pp.push_back(i);
}
for (auto [dif, mx, i]: pos) {
if (cursum > mx) return 0;
cursum -= dif;
pp.push_back(i);
}
perm = pp;
return 1;
}
void solve() {
int n; cin >> n;
vector<tuple<int, int, int>> a;
for (int i = 0; i < n; i++) {
int x, y, z; cin >> x >> y >> z;
a.emplace_back(x, y, z);
}
int lo = 0, hi = 1e18;
vector<int> perm;
while (lo < hi) {
int mid = (lo + hi)/2;
if (ok(mid, n, a, perm)) {
hi = mid;
} else {
lo = mid+1;
}
}
for (int i: perm) cout << i+1 << ' ';
cout << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3392kb
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 8 4 2 7 5 1 9 6
result:
wrong answer Wrong Answer on Case#2