QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686385#6416. Classical Scheduling ProblembadmintonWA 1ms5652kbC++143.3kb2024-10-29 12:00:062024-10-29 12:00:08

Judging History

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

  • [2024-10-29 12:00:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5652kb
  • [2024-10-29 12:00:06]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <ll,ll> pii;
typedef pair <pii,ll> piii;

#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

template<class X, class Y>
    bool minz(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } return false;
    }
template<class X, class Y>
    bool maxz(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } return false;
    }

const int N = 5e5 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;

piii a[N];
int n, t;
priority_queue<pii> q;
int suf[N];

int check(int k){
    if (!k) return 1;

    while (!q.empty()){
        q.pop();
    }

    int sum = 0;
    
    ford (i, n, 1){
        if (i < n){
            q.push({a[i + 1].st.nd, i});
            sum = sum + a[i + 1].st.nd;
        }

        ll need = max (a[i].st.nd - k, 0ll);

        if (need > q.size()){
            suf[i] = 1e15;
            continue;
        }
        while (need < q.size()){
            sum = sum - q.top().st;
            q.pop();
        }
        suf[i] = sum;
    }

    while (!q.empty()){
        q.pop();
    }

    int now = 1;
    int pref = 0;
    
    for (int i = k; i <= n; i++){
        while (now < i){
            q.push({a[now].st.nd, now});
            pref = pref + a[now].st.nd;
            now++;
        }

        while (q.size() > k - 1){
            pref = pref - q.top().st;
            q.pop();
        }

        if (pref + suf[i] + a[i].st.nd <= t){
            return i;
        }
    }
    return 0;
}

bool cmp(piii x, piii y){
    return x.st.nd < y.st.nd;
}

void getans(int k, int p){
    cout << k << "\n";

    if (k == 0){
        cout << "0\n";
        return;
    }

    vector<int> ans;
    
    while (!q.empty()){
        ans.pb(a[q.top().nd].nd);
        q.pop();
    }

    ans.pb(a[p].nd);
    sort(a + 1 + p, a + 1 + n, cmp);
    
    forr (i, p + 1, p + a[p].st.nd - k){
        ans.pb(a[i].nd);
    }

    sort(all(ans));
    cout << ans.size() << "\n";
    
    for (auto p : ans){
        cout << p << " ";
    }
    cout << "\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef kaguya
        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    #endif

    int q;
    cin >> q;
    while (q--){
        cin >> n >> t;
        forr (i, 1, n){
            cin >> a[i].st.nd >> a[i].st.st;
            a[i].nd = i;
        }

        sort(a + 1, a + n + 1);

        int l = 0, r = n;
        while (l < r){
            int mid = (l + r) / 2 + 1;
            if (check(mid)){
                l = mid;
            }
            else{
                r = mid - 1;
            }
        }
        getans(l, check(l));
    }

    return 0;
}
/*



*/


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5652kb

input:

2
4 100
20 1
40 4
60 3
30 3
1 5
10 1

output:

4
40
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 
0
0

result:

wrong answer Integer parameter [name=k] equals to 40, violates the range [0, 4] (test case 1)