3362021-10-14 20:13:25rmlanÜgyeletcpp11Accepted 40/409ms3256 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define ll long long
#define tc int _TC_; cin >> _TC_; while(_TC_--)
using namespace std;
struct jel{
    int k,v,id;
};
bool comp(jel a, jel b){
    return a.k < b.k;
}
bool comp2(pair<int, int> a, pair<int, int> b){
    return a.fi > b.fi;
}
int main(){
    int m,n;
    cin >> m >> n;
    vector<int> ans;
    vector<jel> je(n);
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        je[i].id=i+1;
        je[i].k = a;
        je[i].v = b;
    }
    sort(je.begin(), je.end(), comp);
    queue<jel> q;
    for(int i = 0;  i < n; i++){
        q.push(je[i]);
    }
    priority_queue<pair<int, int>> pq;
    int a=0,b=0;
    for(int i = 1; i <= m; i++){
        while(q.front().k == i){
            pq.push(m_p(q.front().v, q.front().id));
            q.pop();
        }
        if(a < i){
            if(pq.empty()){
                ans.clear();
                break;
            }
            a = pq.top().fi;
            ans.push_back(pq.top().se);
            pq.pop();
        }
        if(b < i){
           if(pq.empty()){
                ans.clear();
                break;
            }
            b = pq.top().fi;
            ans.push_back(pq.top().se);
            pq.pop();
        }
        if(min(a, b) < i){
            ans.clear();
            break;
        }
    }
    cout << ans.size() << endl;
    for(int a:ans){
        cout << a << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1804 KiB
2Accepted0/04ms2292 KiB
3Accepted2/21ms1896 KiB
4Accepted2/21ms1900 KiB
5Accepted2/21ms1904 KiB
6Accepted2/21ms1912 KiB
7Accepted2/21ms1912 KiB
8Accepted2/22ms1952 KiB
9Accepted2/22ms1972 KiB
10Accepted2/21ms1980 KiB
11Accepted2/22ms1988 KiB
12Accepted1/12ms2000 KiB
13Accepted2/23ms2056 KiB
14Accepted2/23ms2260 KiB
15Accepted2/24ms2328 KiB
16Accepted3/38ms2832 KiB
17Accepted3/38ms2860 KiB
18Accepted3/39ms3024 KiB
19Accepted3/38ms3136 KiB
20Accepted3/38ms3256 KiB