#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
{
int C[MXN * 4];
ll S[MXN * 4];
SegTree ()
{
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 &k, int id = 1, int l = 0, int r = MXN)
{
if (k <= 0) return (0LL);
if (C[id] <= k)
{k -= C[id]; return (S[id]);}
return (_Get(k, rc, md, r) + _Get(k, lc, l, md));
}
ll Get(int k)
{
int tmp = k;
assert(C[1] >= tmp);
ll ret = _Get(tmp);
//assert(tmp == 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:52: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:54: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 |
9 ms |
19064 KB |
Output is correct |
2 |
Correct |
19 ms |
19200 KB |
Output is correct |
3 |
Correct |
18 ms |
19048 KB |
Output is correct |
4 |
Incorrect |
17 ms |
19072 KB |
Output isn't correct |
5 |
Correct |
15 ms |
19164 KB |
Output is correct |
6 |
Correct |
19 ms |
19184 KB |
Output is correct |
7 |
Correct |
23 ms |
19192 KB |
Output is correct |
8 |
Correct |
24 ms |
19092 KB |
Output is correct |
9 |
Correct |
25 ms |
19192 KB |
Output is correct |
10 |
Correct |
21 ms |
19200 KB |
Output is correct |
11 |
Correct |
22 ms |
19192 KB |
Output is correct |
12 |
Correct |
26 ms |
19192 KB |
Output is correct |
13 |
Correct |
50 ms |
19428 KB |
Output is correct |
14 |
Correct |
95 ms |
19756 KB |
Output is correct |
15 |
Incorrect |
112 ms |
20308 KB |
Output isn't correct |
16 |
Incorrect |
191 ms |
20556 KB |
Output isn't correct |
17 |
Incorrect |
1650 ms |
20864 KB |
Output isn't correct |
18 |
Incorrect |
1648 ms |
21084 KB |
Output isn't correct |
19 |
Execution timed out |
2037 ms |
21188 KB |
Time limit exceeded |
20 |
Execution timed out |
2011 ms |
21488 KB |
Time limit exceeded |