#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define pii pair < int, int >
const int N = 3e5 + 1;
vector < pii > v;
int ans, u[N];
main()
{
int n, m, s;
cin >> n >> m >> s;
for(int i = 1; i <= n; i++)
{
int a, b;
cin >> a >> b;
v.pb( {a, b} );
ans += a;
}
if(m + s == 0)
{
cout << 0 << endl;
return 0;
}
int cnt = n - m - s;
while(s--)
{
int mx = (int)1e8, id = -1;
mx = -mx;
for(int i = 0; i < n; i++)
{
if(u[i] == 0)
{
if(mx < v[i].sc - v[i].fr)
{
mx = v[i].sc - v[i].fr;
id = i;
}
}
}
//cout << id << endl;
u[id] = 1;
ans += mx;
}
while(cnt--)
{
int mn = (int)1e8, id = -1;
for(int i = 0; i < n; i++)
{
if(u[i] == 0)
{
if(mn > v[i].fr)
{
mn = v[i].fr;
id = i;
}
}
}
//cout << id << endl;
u[id] = 1;
ans -= mn;
}
cout << ans << endl;
}
/*
3 1 1
5 2
4 1
6 4
7 2 3
9 8
10 6
3 5
1 7
5 7
6 3
5 4
*/
Compilation message
school.cpp:19:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Incorrect |
2 ms |
508 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
560 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
564 KB |
Output isn't correct |
7 |
Incorrect |
63 ms |
876 KB |
Output isn't correct |
8 |
Correct |
5 ms |
920 KB |
Output is correct |
9 |
Incorrect |
10 ms |
920 KB |
Output isn't correct |
10 |
Incorrect |
12 ms |
920 KB |
Output isn't correct |
11 |
Incorrect |
76 ms |
932 KB |
Output isn't correct |
12 |
Incorrect |
79 ms |
932 KB |
Output isn't correct |
13 |
Incorrect |
279 ms |
1452 KB |
Output isn't correct |
14 |
Execution timed out |
2045 ms |
1972 KB |
Time limit exceeded |
15 |
Execution timed out |
2057 ms |
2972 KB |
Time limit exceeded |
16 |
Execution timed out |
2048 ms |
3288 KB |
Time limit exceeded |
17 |
Execution timed out |
2050 ms |
3868 KB |
Time limit exceeded |
18 |
Execution timed out |
2054 ms |
4068 KB |
Time limit exceeded |
19 |
Execution timed out |
2054 ms |
4184 KB |
Time limit exceeded |
20 |
Execution timed out |
2045 ms |
5144 KB |
Time limit exceeded |