# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286277 | shrek12357 | Schools (IZhO13_school) | C++14 | 720 ms | 26856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
#define ll long long
bool comp(pair<ll, ll> a, pair<ll, ll> b) {
return (a.second - a.first) > (b.second - b.first);
}
int main() {
int n, m, s;
cin >> n >> m >> s;
multiset<pair<ll, ll>> left;
vector<pair<ll, ll>> schools;
for (int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
left.insert({ a*-1, b });
schools.push_back({ a, b });
}
sort(schools.begin(), schools.end(), comp);
ll ans = 0;
for (int i = 0; i < m; i++) {
ans += left.begin()->first*-1;
left.erase(left.begin());
}
for (int i = 0; i < s; i++) {
if (left.find({ schools[i].first*-1, schools[i].second }) != left.end()) {
ans += schools[i].second;
}
else {
ans += schools[i].second;
ans -= schools[i].first;
ans += left.begin()->first*-1;
left.erase(left.begin());
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |