#include <bits/stdc++.h>
#define int long long
using namespace std;
struct yes
{
int p, v;
};
yes v1[300005];
yes v2[300005];
bool vis1[300005];
bool vis2[300005];
bool luat[300005];
bool cmp(yes a, yes b)
{
return a.v > b.v;
}
bool cmp2(int a, int b)
{
int dif1 = (v1[a].v - v2[a].v), dif2 = (v1[b].v - v2[b].v);
if(dif1 == dif2)
return v1[a].v > v2[a].v;
return dif1 < dif2;
}
bool cmp3(yes a, yes b)
{
return a.v < b.v;
}
signed main()
{
int n, m, s;
cin>>n>>m>>s;
vector<int> p;
int rez = 0;
for(int i = 1; i <= n; i++)
{
cin>>v1[i].v>>v2[i].v;
v1[i].p = v2[i].p = i;
p.push_back(i);
vis1[i] = true;
rez += v1[i].v;
}
sort(p.begin(), p.end(), cmp2);
int cm = n, cs = 0, poz = -1;
while(cm > m && cs < s)
{
poz++;
cm--, cs++;
vis1[p[poz]] = false;
vis2[p[poz]] = true;
rez -= v1[p[poz]].v;
rez += v2[p[poz]].v;
}
if(cm > m)
{
sort(v1 + 1, v1 + n + 1, cmp3);
poz = 0;
while(cm > m)
{
poz++;
if(!vis2[v1[poz].p])
cm--, rez -= v1[poz].v;
}
}
if(cs < s)
{
while(1);
}
cout<<rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
4536 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
8 |
Correct |
3 ms |
4700 KB |
Output is correct |
9 |
Incorrect |
3 ms |
4628 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
4952 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
4708 KB |
Output isn't correct |
13 |
Incorrect |
20 ms |
5548 KB |
Output isn't correct |
14 |
Incorrect |
45 ms |
8380 KB |
Output isn't correct |
15 |
Incorrect |
99 ms |
12460 KB |
Output isn't correct |
16 |
Correct |
96 ms |
12228 KB |
Output is correct |
17 |
Incorrect |
167 ms |
13500 KB |
Output isn't correct |
18 |
Incorrect |
204 ms |
14332 KB |
Output isn't correct |
19 |
Incorrect |
204 ms |
14892 KB |
Output isn't correct |
20 |
Incorrect |
285 ms |
17744 KB |
Output isn't correct |