比赛 贪心题目练习 评测结果 AAAAAAAAAAAAA
题目名称 日光浴 最终得分 100
用户昵称 OTTF 运行时间 0.178 s
代码语言 C++ 内存使用 3.37 MiB
提交时间 2025-03-22 14:34:13
显示代码纯文本

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>

using namespace std;

int c;
int l;
pair<int, int> cow[2525];
int spf[2525];
int cover[2525];
int res;

bool cmp (pair<int, int> one, pair<int, int> two) {
    return one.second < two.second;
}

int main () {
    
    freopen ("tanning.in", "r", stdin);
    freopen ("tanning.out", "w", stdout);
    
    cin >> c >> l;
    for (int i = 1; i <= c; i++) {
        cin >> cow[i].first >> cow[i].second;
    }
    for (int i = 1; i <= l; i++) {
        cin >> spf[i] >> cover[i];
    }
    sort (cow + 1, cow + 1 + c, cmp);
    
    for (int i = 1; i <= c; i++) {
        int now = -1;
        for (int j = 1; j <= l; j++) {
            if (cow[i].first <= spf[j] && spf[j] <= cow[i].second && cover[j] > 0) {
                if (now == -1 || spf[j] < spf[now]) {
                    now = j;
                }
            }
        }
        
        if (now != -1) {
            cover[now]--;
            res++;
        }
    }
    
    cout << res << endl;
    
    return 0;
}