#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 > v1[b].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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
4444 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
8 |
Correct |
3 ms |
4444 KB |
Output is correct |
9 |
Incorrect |
4 ms |
4700 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
4564 KB |
Output isn't correct |
13 |
Incorrect |
27 ms |
5592 KB |
Output isn't correct |
14 |
Incorrect |
46 ms |
8504 KB |
Output isn't correct |
15 |
Incorrect |
95 ms |
11840 KB |
Output isn't correct |
16 |
Correct |
93 ms |
11980 KB |
Output is correct |
17 |
Incorrect |
132 ms |
12384 KB |
Output isn't correct |
18 |
Incorrect |
149 ms |
13200 KB |
Output isn't correct |
19 |
Incorrect |
177 ms |
13756 KB |
Output isn't correct |
20 |
Incorrect |
183 ms |
17656 KB |
Output isn't correct |