이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const bool typetest = 0;
const int N = 2e2 + 5;
const ll Inf = 1e17;
int n, m;
struct Pakage
{
ll c, v;
bool operator<(const Pakage &a) const
{
return c < a.c;
}
} a[N];
ll dp[N][N][N];
void Read()
{
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i].v >> a[i].c;
}
template <class T>
void Max(T &x, T y)
{
if (x < y)
x = y;
}
void Solve()
{
fill_n(&dp[0][0][0], N * N * N, -Inf);
dp[1][0][0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 0; j < i && j <= m; ++j)
for (int t = 0; t <= 2 * j && t <= m; t += 2)
{
//cout << i << " " << j << " " << t << ": " << dp[i][j][t] << "\n";
Max(dp[i + 1][j][t], dp[i][j][t]);
if (j == m - 1 || t > 2)
Max(dp[i + 1][j + 1][t - 2], dp[i][j][t] + a[i].v - 2 * a[i].c);
if (t > 0)
Max(dp[i + 1][j + 1][t], dp[i][j][t] + a[i].v);
Max(dp[i + 1][j + 1][t + 2], dp[i][j][t] + a[i].v + 2 * a[i].c);
}
cout << dp[n + 1][m][0];
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |