#include<bits/stdc++.h>
#define lc (id << 1)
#define rc (id << 1 ^ 1)
#define md ((l + r) >> 1)
using namespace std;
typedef long long ll;
template < int MXN >
struct SegTree
{
ll K = 0;
ll C[MXN * 8];
ll S[MXN * 8];
SegTree ()
{
K = 0;
memset(C, 0, sizeof(C));
memset(S, 0, sizeof(S));
}
void Add(int i, int val, int id = 1, int l = 0, int r = MXN)
{
if (r - l < 2)
{
S[id] += 1LL * val * i;
C[id] += val; return ;
}
if (i < md)
Add(i, val, lc, l, md);
else
Add(i, val, rc, md, r);
C[id] = C[lc] + C[rc];
S[id] = S[lc] + S[rc];
}
ll _Get(int id = 1, int l = 0, int r = MXN)
{
if (K == 0)
return (0LL);
if (C[id] <= K)
{
K -= C[id];
return (S[id]);
}
if (r - l < 2)
{
ll ret = K * l;
K = 0;
return (ret);
}
return (_Get(rc, md, r) + _Get(lc, l, md));
}
ll Get(int k)
{
K = k;
ll ret = _Get();
assert(K == 0);
return (ret);
}
};
const int N = 300005, MXN = 100005;
int n, R, M;
pair < int , int > A[N];
int32_t main()
{
scanf("%d%d%d", &n, &R, &M);
for (int i = 0; i < n; i++)
scanf("%d%d", &A[i].first, &A[i].second);
sort(A, A + n); reverse(A, A + n);
SegTree < MXN * 2 > P, S;
for (int i = 0; i < n; i++)
S.Add(A[i].second, 1);
ll Mx = 0, sum = 0;
for (int i = 0; i < R + M; i++)
{
sum += A[i].first;
S.Add(A[i].second, -1);
P.Add(A[i].second - A[i].first + MXN, 1);
if (i >= R - 1)
Mx = max(Mx, sum + P.Get(i + 1 - R) - 1LL * (i + 1 - R) * MXN + S.Get(M - (i + 1 - R)));
}
return !printf("%lld\n", Mx);
}
Compilation message
school.cpp: In function 'int32_t main()':
school.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &R, &M);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
school.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &A[i].first, &A[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
50424 KB |
Output is correct |
2 |
Correct |
45 ms |
50424 KB |
Output is correct |
3 |
Correct |
40 ms |
50428 KB |
Output is correct |
4 |
Correct |
40 ms |
50424 KB |
Output is correct |
5 |
Correct |
37 ms |
50424 KB |
Output is correct |
6 |
Correct |
43 ms |
50432 KB |
Output is correct |
7 |
Correct |
48 ms |
50424 KB |
Output is correct |
8 |
Correct |
41 ms |
50424 KB |
Output is correct |
9 |
Correct |
43 ms |
50596 KB |
Output is correct |
10 |
Correct |
52 ms |
50424 KB |
Output is correct |
11 |
Correct |
51 ms |
50436 KB |
Output is correct |
12 |
Correct |
47 ms |
50424 KB |
Output is correct |
13 |
Correct |
83 ms |
50680 KB |
Output is correct |
14 |
Correct |
105 ms |
51068 KB |
Output is correct |
15 |
Correct |
135 ms |
51704 KB |
Output is correct |
16 |
Correct |
241 ms |
51836 KB |
Output is correct |
17 |
Correct |
259 ms |
52092 KB |
Output is correct |
18 |
Correct |
221 ms |
52352 KB |
Output is correct |
19 |
Correct |
263 ms |
52472 KB |
Output is correct |
20 |
Correct |
251 ms |
52708 KB |
Output is correct |