[백준] 2109 순회강연
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n;
cin >> n;
vector<pair<int, int>> vec;
int maxd = -1;
for (int i = 0; i < n; ++i) {
int p, d;
cin >> p >> d;
maxd = max(maxd, d);
vec.push_back({ d, p });
}
int income = 0;
vector<bool> valid(n, true);
int time = maxd;
while (time > 0) {
int maxp = -1;
int maxpIdx = 0;
bool flag = false;
for (int i = 0; i < n; ++i) {
if (vec[i].first < time) continue;
if (!valid[i]) continue;
if (vec[i].second > maxp) {
maxp = vec[i].second;
maxpIdx = i;
flag = true;
}
}
if (flag) {
income += maxp;
valid[maxpIdx] = false;
}
time--;
}
cout << income;
return 0;
}