# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1040430 |
2024-08-01T03:56:28 Z |
vjudge1 |
Schools (IZhO13_school) |
C++17 |
|
73 ms |
10192 KB |
#include <bits/stdc++.h>
#define Y8o "Schools"
#define maxn (int) 3e5 + 5
#define ll long long
#define pii pair<ll, ll>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define f first
#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
if(fopen(Y8o".inp", "r"))
{
freopen(Y8o".inp", "r", stdin);
// freopen(Y8o".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
int n, m, t;
pii a[maxn];
ll dp[maxn][2];
void solve()
{
cin >> n >> m >> t;
for(int i = 1; i <= n; i ++) cin >> a[i].f >> a[i].s;
sort(a + 1, a + n + 1, [](pii x, pii y) {
return x.f - x.s == y.f - y.s ? x.f > y.f : x.f - x.s > y.f - y.s;
});
ll sum = 0;
priority_queue<int> q;
for(int i = 1; i <= n; i ++) {
q.push(-a[i].f), sum += a[i].f;
if(q.size() < m) dp[i][0] = -1e18;
else if(q.size() == m) dp[i][0] = sum;
else sum -= -q.top(), q.pop(), dp[i][0] = sum;
dp[i][0] = max(dp[i][0], dp[i - 1][0]);
}
while(q.size()) q.pop();
sum = 0;
for(int i = n; i >= 1; i --) {
q.push(-a[i].s), sum += a[i].s;
if(q.size() < t) dp[i][1] = -1e18;
else if(q.size() == t) dp[i][1] = sum;
else sum -= -q.top(), q.pop(), dp[i][1] = sum;
dp[i][1] = max(dp[i][1], dp[i + 1][1]);
}
ll ans = 0;
for(int i = 0; i <= n; i ++) {
ans = max(ans, dp[i][0] + dp[i + 1][1]);
}
cout << ans;
}
int main()
{
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --) {
solve();
}
ctime();
return 0;
}
Compilation message
school.cpp: In function 'void solve()':
school.cpp:52:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | if(q.size() < m) dp[i][0] = -1e18;
| ~~~~~~~~~^~~
school.cpp:53:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | else if(q.size() == m) dp[i][0] = sum;
| ~~~~~~~~~^~~~
school.cpp:62:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | if(q.size() < t) dp[i][1] = -1e18;
| ~~~~~~~~~^~~
school.cpp:63:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
63 | else if(q.size() == t) dp[i][1] = sum;
| ~~~~~~~~~^~~~
school.cpp: In function 'void iof()':
school.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(Y8o".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
9 ms |
4956 KB |
Output is correct |
14 |
Correct |
17 ms |
4820 KB |
Output is correct |
15 |
Correct |
38 ms |
8660 KB |
Output is correct |
16 |
Correct |
38 ms |
9940 KB |
Output is correct |
17 |
Correct |
52 ms |
9168 KB |
Output is correct |
18 |
Correct |
62 ms |
9172 KB |
Output is correct |
19 |
Correct |
67 ms |
9548 KB |
Output is correct |
20 |
Correct |
73 ms |
10192 KB |
Output is correct |