# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
286184 | shrek12357 | 학교 설립 (IZhO13_school) | C++14 | 748 ms | 22712 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
int main() {
int n, m, s;
cin >> n >> s >> m;
vector<pair<int, int>> music;
vector<pair<int, int>> nums;
multiset<pair<int, int>> left;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
nums.push_back({ a, b });
music.push_back({ b, a });
left.insert({ -1*b, a });
}
sort(nums.begin(), nums.end());
sort(music.begin(), music.end());
int curIdx = n - m - 1;
//int bigIdx = n - 1;
int ans = 0;
for(int i = nums.size() - 1; i >= 0; i--){
if (s <= 0) {
while (m > 0) {
ans += -1 * left.begin()->first;
left.erase(left.begin());
m--;
}
break;
}
if (curIdx >= 0 && nums[i].second < music[curIdx].first) {
s--;
ans += nums[i].first;
}
else {
int num1 = nums[i].first;
if (i - s >= 0) {
num1 -= nums[i - s].first;
}
int num2 = nums[i].second;
if (curIdx >= 0) {
num2 -= music[curIdx].first;
}
if (num1 > num2) {
curIdx--;
s--;
ans += nums[i].first;
}
else {
ans += nums[i].second;
m--;
}
}
left.erase(left.find({ nums[i].second * -1, nums[i].first }));
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |