求帮忙

Mo012105023 2021-07-13 19:02:33 8

这道题用freopen怎么做?在线等大神求解!!!!!!!!!!!

{{ vote && vote.total.up }}

共 1 条回复

raoyiou
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e3 + 5;
struct pre 
{
    int id;
    int sco;
} a[MAXN];

bool cmp(pre x, pre y) 
{
    if (x.sco == y.sco) return x.id < y.id;
    return x.sco > y.sco;
}

int main() 
{
    freopen("B.in", "r", stdin);
    freopen("B.out", "w", stdout);
    
    int n, m;
	int k;
	int ans = 0;
    
    cin >> n >> m;
    for (int i = 1; i <= n; i++) 
        cin >> a[i].id >> a[i].sco;
    
    sort(a + 1, a + n + 1, cmp);
    
    k = floor(m * 1.5);
    
    for (int i = 1; i <= n; i++) 
        if (a[i].sco >= a[k].sco)
            ans++;
    
    cout << a[k].sco << ' ' << ans << endl;
    for (int i = 1; i <= ans; i++) 
        cout << a[i].id << ' ' << a[i].sco << endl;
    return 0;
}