Submission

Status:
PPPPPPPPPP

Score: 100

User: Whally

Problemset: ถังดักนิวทริโน

Language: cpp

Time: 0.002 second

Submitted On: 2025-04-14 13:06:18

#include <bits/stdc++.h>
using namespace std;
struct G{
    int bo, cnt;
    bool operator < (const G&o) const {
        if (cnt != o.cnt) return cnt < o.cnt;
        else return bo < o.bo;
    }
};
priority_queue<G> col;
int a[310], b[310], c[310];
int p[310];
bitset<310> mark;
set<int> hee;
vector<int> seg[310], ans;

int fr(int cum, int v)
{
    seg[cum].push_back(v);
    if (p[cum] == cum){
        return cum;
    }
    else{
        return fr(p[cum], v);
    }
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= n; i++){
        int mn = 1e9, idx = i;
        for (int j = 1; j <= n; j++){
            if (i == j) continue;
            if (a[j] <= a[i] && b[j] >= b[i]){
                int of = (a[i] - a[j]) + (b[j] - b[i]);
                if (of < mn){ mn = of; idx = j; }
            }
        }
        p[i] = idx;
    }

    for (int i = 1; i <= m; i++){
        int x; cin >> x;
        fr(x,x);
    }
    for (int i = 1; i <= n; i++){
        col.push({i,(int)seg[i].size()});
    }
    while (!col.empty()){
        bool ch = 1;
        if (!seg[col.top().bo].size()){ col.pop(); continue;}
        for (auto x : seg[col.top().bo]){
            if (mark[x]){ch = 0; break;}
            mark[x] = 1; 
        }
        if (ch) ans.push_back(col.top().bo);
        col.pop();
    }
    sort(ans.begin(), ans.end());
    cout << (int)ans.size() << "\n";
    for (auto x : ans){
        cout << x << " ";
    }

    return 0;
}