# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
518513 |
2022-01-24T02:30:29 Z |
uHyHn |
Schools (IZhO13_school) |
C++14 |
|
125 ms |
262148 KB |
#include<bits/stdc++.h>
//IBOW
#define Task "IZHO13_SCHOOL"
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define eb emplace_back
#define ll long long
using namespace std;
const int N = 3e5 + 10;
const int inf = 2e9 + 10;
const ll INF = 2e18 + 10;
const int MOD = 1e9 + 7;
/*
*/
int n, A[N], B[N], m, s, dp[410][410][410];
ll f0pre[N], f0suf[N], f1pre[N], f1suf[N];
void Deogiaibalamcho()
{
cin >> n >> m >> s;
for (int i = 1; i <= n; ++i) cin >> A[i] >> B[i];
if (n <= 400)
{
fill(&dp[0][0][0], &dp[0][0][0] + 410 * 410 * 410, -inf);
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++i)
{
for (int sum_m = 0; sum_m <= m; ++sum_m)
for (int sum_s = 0; sum_s <= s; ++sum_s)
{
if (dp[i - 1][sum_m][sum_s] != inf)
{
dp[i][sum_m + 1][sum_s]
= max(dp[i - 1][sum_m][sum_s] + A[i], dp[i][sum_m + 1][sum_s]);
dp[i][sum_m][sum_s + 1]
= max(dp[i - 1][sum_m][sum_s] + B[i], dp[i][sum_m][sum_s + 1]);
dp[i][sum_m][sum_s]
= max(dp[i - 1][sum_m][sum_s], dp[i][sum_m][sum_s]);
}
}
}
cout << dp[n][m][s];
} else if (min(s, m) == 1)
{
priority_queue<int, vector<int>, greater<int>> pq;
for (int i = 1; i <= n; ++i)
{
pq.push(A[i]);
f0pre[i] = f0pre[i - 1] + A[i];
if (sz(pq) > m) {
f0pre[i] -= pq.top();
pq.pop();
}
}
while (!pq.empty()) pq.pop();
for (int i = n; i >= 1; --i)
{
pq.push(A[i]);
f0suf[i] = f0suf[i + 1] + A[i];
if (sz(pq) > m) {
f0suf[i] -= pq.top();
pq.pop();
}
}
while (!pq.empty()) pq.pop();
for (int i = 1; i <= n; ++i)
{
pq.push(B[i]);
f1pre[i] = f1pre[i - 1] + B[i];
if (sz(pq) > s)
{
f1pre[i] -= pq.top();
pq.pop();
}
}
while (!pq.empty()) pq.pop();
for (int i = 1; i <= n; ++i)
{
pq.push(B[i]);
f1suf[i] = f1suf[i + 1] + B[i];
if (sz(pq) > s)
{
f1suf[i] -= pq.top();
pq.pop();
}
}
if (m == 1)
{
ll ans = 0;
for (int i = 1; i <= n; ++i)
{
ans = max(ans, A[i] + f1suf[i + 1] + f1pre[i - 1]);
}
cout << ans;
} else
{
ll ans = 0;
for (int i = 1; i <= n; ++i)
{
ans = max(ans, B[i] + f0pre[i - 1] + f0suf[i + 1]);
}
cout << ans;
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(Task".inp", "r"))
{
freopen(Task".inp", "r", stdin);
// freopen(Task".out", "w", stdout);
}
int t = 1;
//cin >> t;
while (t--) Deogiaibalamcho();
return 0;
}
Compilation message
school.cpp: In function 'int32_t main()':
school.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
125 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
112 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Runtime error |
114 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Runtime error |
125 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Runtime error |
111 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Runtime error |
117 ms |
262148 KB |
Execution killed with signal 9 |
6 |
Runtime error |
114 ms |
262148 KB |
Execution killed with signal 9 |
7 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
396 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
408 KB |
Output isn't correct |
13 |
Incorrect |
6 ms |
976 KB |
Output isn't correct |
14 |
Incorrect |
12 ms |
1744 KB |
Output isn't correct |
15 |
Incorrect |
22 ms |
3284 KB |
Output isn't correct |
16 |
Incorrect |
25 ms |
3656 KB |
Output isn't correct |
17 |
Incorrect |
32 ms |
4692 KB |
Output isn't correct |
18 |
Incorrect |
33 ms |
4960 KB |
Output isn't correct |
19 |
Incorrect |
40 ms |
5332 KB |
Output isn't correct |
20 |
Incorrect |
42 ms |
6148 KB |
Output isn't correct |