# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
635092 | pragmatist | 학교 설립 (IZhO13_school) | C++17 | 2087 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define x first
#define y second
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define ld long double
#define nl "\n"
using namespace std;
using pii = pair<int, int>;
const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
const int MOD = (int)1e9 + 7;
const int M = (int)5e4 + 7;
int n, m, s, a[N], b[N];
void solve() {
cin >> n >> m >> s;
for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
ll dp[m + 1][s + 1], pd[m + 1][s + 1];
for(int j = 0; j <= m; ++j)
for(int k = 0; k <= s; ++k)
dp[j][k] = pd[j][k] = -INF;
dp[0][0] = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= m; ++j) {
for(int k = 0; k <= s; ++k) {
pd[j][k] = max({dp[j][k], (j == 0 ? -INF : dp[j - 1][k] + a[i]), (k == 0 ? -INF : dp[j][k - 1] + b[i])});
}
}
for(int j = 0; j <= m; ++j) {
for(int k = 0; k <= s; ++k) {
dp[j][k] = pd[j][k];
pd[j][k] = -INF;
}
}
dp[0][0] = 0;
}
cout << dp[m][s] << nl;
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
while(test--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |