#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pq priority_queue
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
struct ritul
{
int Limit;
int sum;
pq<int> chungus;
void init(int x)
{
Limit = x;
while(!chungus.empty())
chungus.pop();
sum = 0;
return;
}
void push(int x)
{
chungus.push(-x);
sum+=x;
if(chungus.size() > Limit)
{
sum+=chungus.top();
chungus.pop();
}
return;
}
int ans()
{
return sum;
}
};
signed main()
{
fast();
ritul work;
int n, A, B;
cin >> n >> A >> B;
vector<int> a(n+1);
vector<int> b(n+1);
vector<in> c(n+1);
for(int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
c[i] = {i, b[i]-a[i]};
}
sort(c.begin(), c.end());
vector<int> d(n+1, 0);
vector<int> e(n+1, 0);
work.init(A);
for(int i = 1; i <= n; i++)
{
work.push(a[c[i].f]);
d[i] = work.ans();
}
work.init(B);
for(int i = n; i >= 1; i--)
{
work.push(b[c[i].f]);
e[i] = work.ans();
}
int ans = -1;
for(int i = 0; i < n; i++)
ans = max(ans, d[i]+e[i+1]);
cout << ans << "\n";
return 0;
}
Compilation message
school.cpp: In member function 'void ritul::push(long long int)':
school.cpp:30:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
30 | if(chungus.size() > Limit)
| ~~~~~~~~~~~~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
13 |
Incorrect |
10 ms |
2908 KB |
Output isn't correct |
14 |
Incorrect |
20 ms |
5200 KB |
Output isn't correct |
15 |
Incorrect |
32 ms |
9772 KB |
Output isn't correct |
16 |
Incorrect |
43 ms |
13008 KB |
Output isn't correct |
17 |
Incorrect |
66 ms |
14284 KB |
Output isn't correct |
18 |
Incorrect |
76 ms |
15664 KB |
Output isn't correct |
19 |
Incorrect |
79 ms |
16620 KB |
Output isn't correct |
20 |
Incorrect |
91 ms |
19148 KB |
Output isn't correct |