QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#174237#6414. Classical Maximization Problempikachu_coderWA 1ms4456kbC++144.7kb2023-09-10 05:45:082023-09-10 05:45:08

Judging History

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

  • [2023-09-10 05:45:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4456kb
  • [2023-09-10 05:45:08]
  • 提交

answer

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

1
4 100
25 1
25 1
25 1
25 4
4
4
4 3 2 1
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define pii pair<int, int>
#define pil pair<int, ll>

const int maxn = 200001;
struct topic{
    int ind; ll time; int confident; 
};
bool cmp(topic a, topic b){
    return a.confident < b.confident; 
}
int n; ll t; 
vector<topic> topics;
vl rt(maxn, 0LL);

int last_test; int last_req; 
bool valid(int ind){
    //keep largest time on top
    ll sm = 0LL; 
    priority_queue<int> bst; //stores times, pushed out times get put into rest, nbst afterwards is compared with rest
    multiset<int> nbst; 
    multiset<int> rest; 
    int ps = 0; 
    for(int a = 0; a < n; a++){
        rest.insert(topics[a].time);
    }
    for(int req = ind; req <= n; req++){
        //first ind courses must have a confidence of less than or equal to req, next req-ind courses can be from either pool of confident/not confident --> keep ind courses in a priority queue, the remaining req-ind in an ordered set
        //all courses with requirement equal to req are removed from nbst/rest and compared against bst, all courses pushed out of bst are reconsidered against nbst, all courses rejected by nbst are replaced back into pool, topics sorted by requirement --> can values be discarded from rest? 
        //cout << "   TESTING REQ " << req << " FOR IND " << ind << endl; 
        while(ps < n && topics[ps].confident <= req){
            //cout << " adding " << topics[ps].time << " to best\n";
            bst.push(topics[ps].time); sm += topics[ps].time; 
            auto lwr = rest.lower_bound(topics[ps].time);
            if(lwr != rest.end() && *lwr == topics[ps].time){
                rest.erase(lwr);
            } else{
                sm -= topics[ps].time; 
                lwr = nbst.lower_bound(topics[ps].time);
                nbst.erase(lwr); //guaranteed to exist in this set
            }
            while(bst.size() > ind){
                //cout << " removing " << bst.top() << " from best\n";
                sm -= bst.top();
                rest.insert(bst.top()); bst.pop(); 
            }
            ps++; 
        }
        while(nbst.size() < req-ind){
            auto low = rest.begin(); 
            nbst.insert(*low);
            rest.erase(low); sm += (*low);
        }
        while(nbst.size() > req-ind){ //add lowest from rest
            auto high = nbst.end(); --high; 
            rest.insert(*high);
            nbst.erase(high); sm -= (*high);
        }
        //for(ll ite : nbst) cout << ite << ". "; cout << endl; 
        //for(ll ite : rest) cout << ite << ".. "; cout << endl; 
        //cout << "   TIME IS " << sm << " best " << bst.size() << endl; 
        if(sm <= t && bst.size() >= ind){
            last_test = ind; last_req = req; 
            return true; 
        }
    }
    return false; 
}
void build(){ //study ind lowest topics with b <= req, and take the remaining 
    priority_queue<pii> bst; //time, ind
    multiset<pii> rest; //time, ind
    int ps = 0; 
    for(int a = 0; a < n; a++){
        rest.insert({topics[a].time, topics[a].ind});
    }
    while(ps < n && topics[ps].confident <= last_req){
        bst.push({topics[ps].time, topics[ps].ind}); 
        rest.erase(rest.lower_bound({topics[ps].time, topics[ps].ind}));
        while(bst.size() > last_test){
            rest.insert(bst.top()); bst.pop(); 
        }
        ps++; 
    }
    int taken = 0; 
    while(!bst.empty()){
        rt[taken++] = bst.top().second; bst.pop(); 
    }
    auto it = rest.begin(); 
    while(taken < last_req){
        rt[taken++] = it->second; ++it; 
    }
}
int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
	int nc; cin >> nc; 
    for(int cc = 0; cc < nc; cc++){
        cin >> n >> t; 
        topics = vector<topic>(n, {0LL, -1});
        for(int a = 0; a < n; a++){
            cin >> topics[a].time >> topics[a].confident; topics[a].ind = a;
        } sort(topics.begin(), topics.end(), cmp); //sorted by confidence 
        int mn = 0; int mx = n+1; //number of confident classes
        for(int dv = 0; dv < 20; dv++){
            int md = (mn+mx)/2; //cout << md << endl; 
            if(valid(md)) mn = md; 
            else mx = md-1; 
        } cout << mn << "\n";

        build(); 
        cout << last_req << "\n";
        for(int a = 0; a < last_req; a++){
            if(a > 0) cout << " ";
            cout << rt[a]+1; 
        } cout << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2
0 0
0 1
1 0
1 1
2
0 0
0 1
0 2
0 3
2
0 0
1 1
2 2
3 3

output:

1
1
1
0
0

1
1
1

result:

wrong answer pair 1 is 1=1 (test case 1)