跳到正文

题解

CF416C Booking System

zzmbj约 3 分钟
原文
文章信息与版本

文章信息

收录
2026年2月3日
更新
2026年2月8日
篇幅
约 3 分钟
题目
CF416C

版本

  1. v1当前

CF416C Booking System

你这能 A 我吃。

——某位不便透露名字的人士

思路

先考虑收益高的订单。对每个可以实现的订单,分配最接近它所需的座位数且容量最小的空闲桌子。注意最后输出原始的编号。

代码

应该是题解区比较简洁的了。

C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 10;
int n, k, r[N], m_r, pos, m, s; //max_r
bool vis[N];
vector<pair<int, int>> ans;
struct t{int c, p, id;} a[N];
bool cmp(t x, t y) {return x.p > y.p;}
int main()
{
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i].c >> a[i].p, a[i].id = i;
    sort(a+1, a+n+1, cmp);
    cin >> k;
    for(int i=1; i<=k; i++) cin >> r[i], m_r = max(r[i], m_r);
    for(int i=1; i<=n; i++)
    {
        pos=-1;
        if(a[i].c > m_r) continue;
        for(int j=1; j<=k; j++)
            if(!vis[j] && r[j] >= a[i].c)
                if(pos == -1 || r[j] < r[pos])
            		pos = j;
        if(pos == -1) continue;
        vis[pos] = 1;
        m++;
        s += a[i].p;
        ans.push_back({a[i].id, pos});
    }
    cout << m << ' ' << s << '\n';
    for(auto& [x, y] : ans) {cout << x << ' ' << y << '\n';}
    return 0;
}

submission⁡\color{52c41a}\operatorname{submission}

你吃吧。

原文