#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct ABC {
int sum, fir, sec, ind;
};
bool comp (ABC a, ABC b) {
return a.sum>b.sum;
}
ABC v[300005];
pair < int, int > se[300005], fi[300005];
bool used[300005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, m, s;
cin >> n >> m >> s;
for (int k=1; k<=n; k++) {
cin >> v[k].fir;
cin >> v[k].sec;
fi[k].first=v[k].fir;
fi[k].second=k;
se[k].first=v[k].sec;
se[k].second=k;
v[k].sum=v[k].fir+v[k].sec;
v[k].ind=k;
}
sort(v+1,v+1+n, comp);
int k=1; ll ans=0;
while (k<=n && s && m) {
ans+=max(v[k].sec+v[k+1].fir,v[k].fir+v[k+1].sec);
used[v[k].ind]=true;
used[v[k+1].ind]=true;
m--;
s--;
}
if (m==0) {
sort(se+1,se+1+n);
reverse(se+1,se+1+n);
for (int i=1; i<=n; i++) {
if (s==0) break;
if (used[se[i].second]) continue;
ans+=se[i].first;
s--;
}
cout << ans;
return 0;
}
if (s==0) {
sort(fi+1,fi+1+n);
reverse(fi+1,fi+1+n);
for (int i=1; i<=n; i++) {
if (s==0) break;
if (used[fi[i].second]) continue;
ans+=fi[i].first;
s--;
}
cout << ans;
return 0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
448 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
544 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
672 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
748 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
748 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
748 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
748 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
748 KB |
Output isn't correct |
13 |
Incorrect |
17 ms |
1772 KB |
Output isn't correct |
14 |
Incorrect |
37 ms |
3052 KB |
Output isn't correct |
15 |
Incorrect |
74 ms |
5560 KB |
Output isn't correct |
16 |
Incorrect |
89 ms |
6252 KB |
Output isn't correct |
17 |
Incorrect |
97 ms |
7588 KB |
Output isn't correct |
18 |
Incorrect |
106 ms |
8264 KB |
Output isn't correct |
19 |
Incorrect |
115 ms |
8700 KB |
Output isn't correct |
20 |
Incorrect |
132 ms |
10072 KB |
Output isn't correct |