求救!正在渡劫!

B4085 [语言月赛 202412] 顽强拼搏奖的四种发法

MSJ2013 @ 2025-01-10 20:19:25


#include<bits/stdc++.h>
using namespace std;
#define L long long
L n, t, p, k, i1, i2, i3, i4;
L x[101];
int x1[101][101][2];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t >> p >> k;
    int l = t, o[n + 1], id[n + 1], Tm[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> id[i] >> Tm[i] >> o[i];
        if (o[i] == 1) {
            if (x1[id[i]][Tm[i]][0] == 0) {
                x[id[i]]++;
                if (x[id[i]] == 1)l--;
                x1[id[i]][Tm[i]][0] = 1;
                x1[id[i]][Tm[i]][1] = i;
                if (l == 0 && i4 == 0)i4 = id[i];
            } else continue;
        }
    }
    int k1=0,op[t+1];
    for (int i = 1; i <= t; i++) {
        if(x[i]>=k)op[++k1]=i;
    }
    for (int i = n; i > 0; i--) {
        if (o[i] == 1) {
            if (i1 == 0)i1 = id[i];
            if (x1[id[i]][Tm[i]][1] == i) {
                if (i2 == 0)i2 = id[i];
                bool flag = 0;
                for (int j = 1; j <= k1; j++) {
                    if (op[j] == id[i]) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0) {
                    i3 = id[i];
                    break;
                }
            }
        }
    }
    cout << i1 << ' ' << i2 << ' ' << i3 << ' ' << i4;
    return 0;
}

|