QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276526#7750. Revenge on My Bossreal_sigma_teamWA 1ms5500kbC++201.7kb2023-12-05 22:25:012023-12-05 22:25:02

Judging History

你现在查看的是最新测评结果

  • [2023-12-05 22:25:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5500kb
  • [2023-12-05 22:25:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
 
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using ll = long long;
const int N = 1e5 + 5;
ll a[N], b[N], c[N];
int ab[N], ba[N];
int S1, S2, n;
int ans[N];
ll bound[N];
ll B = 0;
bool check(ll cost){
    ll ah = 0, bh = 0;
    for(int i = 0; i < n; i++){
        bound[i] = cost / c[i] - B - a[i];
    }
    sort(ab, ab + S1, [&](int x, int y){
        return bound[x] > bound[y];
    });
    int c = 0;
    for(int i = 0; i < S1; i++){
        if(ah - bh <= bound[ab[i]]){
            ah += a[ab[i]];
            bh += b[ab[i]];
            ans[c++] = ab[i] + 1;
        }else{
            return false;
        }
    }
    sort(ba, ba + S2, [&](int x, int y){
        return bound[x] + a[x] - b[x] < bound[y] + a[y] - b[y];
    });
    for(int i = 0; i < S2; i++){
        if(ah - bh <= bound[ba[i]]){
            ah += a[ba[i]];
            bh += b[ba[i]];
            ans[c++] = ba[i] + 1;
        }else{
            return false;
        }
    }
    return true;
}   

void solve() {
    cin >> n;

    S1 = S2 = 0;

    for(int i =0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
        if(a[i] - b[i] >= 0)
            ab[S1++] = i;
        else
            ba[S2++] = i;
        B += b[i];
    }

    ll l = -1, r = 1e18;
    while(r - l > 1){
        ll mid = (l + r) >> 1;
        if(check(mid))
            r = mid;
        else
            l = mid;
    }
    check(r);
    for(int i = 0; i < n; i++){
        cout << ans[i] << ' ';
    }
    cout << '\n';
}
 
int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    int t = 1;
    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: 5500kb

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:

4 1 2 3 
6 1 7 9 5 2 8 4 3 

result:

wrong answer Wrong Answer on Case#1