# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88949 | Lkvatashidze | Schools (IZhO13_school) | C++17 | 5 ms | 844 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 <bits/stdc++.h>
#define ll long long
using namespace std;
pair < ll, ll > a[300005];
pair < ll, ll > b[300005];
ll used[300005];
ll n, m, s;
ll ans, ans0;
int main() {
freopen ("school.in", "r", stdin);
freopen ("school.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> s;
for (ll k=1; k<=n; k++) {
ll x, y;
cin >> x >> y;
a[k].first=x;
a[k].second=k;
b[k].first=y;
b[k].second=k;
}
sort (a+1,a+1+n);
sort (b+1,b+1+n);
for (ll k=n; k>=n-m+1; k--) {
ans+=a[k].first;
used[a[k].second]=true;
}
reverse(b+1,b+1+n);
ll i=1; ll j=1;
while (i<=s && j<=n) {
if (used[b[j].second]) {
j++;
continue;
}
ans+=b[j].first;
used[b[j].second]=true;
j++; i++;
}
for (ll k=1; k<=n; k++)
used[k]=false;
sort (a+1,a+1+n);
sort (b+1,b+1+n);
for (ll k=n; k>=n-s+1; k--) {
ans0+=b[k].first;
used[b[k].second]=true;
}
reverse(a+1,a+1+n);
i=1; j=1;
while (i<=m && j<=n) {
if (used[a[j].second]) {
j++;
continue;
}
ans0+=a[j].first;
used[b[j].second]=true;
j++; i++;
}
cout << max(ans,ans0);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |