比赛 20251001国庆欢乐赛1 评测结果 AWWWWWWWWW
题目名称 有n种物品 最终得分 10
用户昵称 xuyuqing 运行时间 0.430 s
代码语言 C++ 内存使用 4.08 MiB
提交时间 2025-10-01 10:09:02
显示代码纯文本

#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

const int N = 114514;

int n;
int a[N];
int b[N];
struct pick {
    bool first;
    int num;
    int id;
    
    pick (bool first, int num, int id) {
        this->first = first;
        this->num = num;
        this->id = id;
    }
    bool operator< (const pick other) const {
        if (num != other.num) {
            return num < other.num;
        }
        return first > other.first;
    }
};
priority_queue<pick> pq;
long long res;

int main () {
    
    freopen ("nit.in", "r", stdin);
    freopen ("nit.out", "w", stdout);
    
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        pq.emplace(true, a[i], i);
    }
    
    int i = 0;
    while (!pq.empty()) {
        i++;
        pick p = pq.top();
        pq.pop();
        
        res += ((i % 2) ? 1 : -1) * p.num;
        
        if (p.first) {
            pq.emplace(false, b[p.id], p.id);
        }
    }
    
    cout << res << endl;
    
    return 0;
}