Help us understand the problem. What is going on with this article?

# abc 095 累積dp

More than 1 year has passed since last update.

C
ファーストフードチェーン「ピザアット」のメニューは「A ピザ」「B ピザ」「AB ピザ」の 3 種類です。A ピザと B ピザは全く異なるピザで、これらをそれぞれ半分に切って組み合わせたものが AB ピザです。A ピザ、B ピザ、AB ピザ 1 枚あたりの値段はそれぞれ A 円、B 円、C 円です。

```#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
int main() {
int A, B, C, X, Y;
cin >> A >> B >> C >> X >> Y;
if (A + B < 2*C) {
cout << A * X + B * Y << endl;
}
else {
if (X < Y) {
int ans1 = 2 * Y*C;
int ans2 = 2 * X*C + (Y - X)*B;
if (ans1 < ans2)
cout << ans1 << endl;
else
cout << ans2 << endl;
}
else {
int ans3 = 2 * X*C;
int ans4 = 2 * Y*C + (X - Y)*A;
if (ans3 < ans4)
cout << ans3 << endl;
else
cout << ans4 << endl;
}
}
return 0;
}
```

Cにしては優しめ？

D

```#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
if (x < y)swap(x, y);
if (y == 0)return x;
return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
ll N, C;
cin >> N >> C;
vector<ll>x(N + 2), v(N + 2);
for (int i = 1; i <= N; ++i) {
cin >> x[i] >> v[i];
}
x[0] = 0;
x[N + 1] = C;
ll cal = 0;
vector<vector<ll>>dp(2, vector<ll>(100010, 0));
for (ll i = 1; i <= N; ++i) {
cal -= x[i] - x[i - 1];
cal += v[i];
dp[0][i] = max(dp[0][i - 1], cal);
}
//ここでそれまでのカロリーの最大値をメモ
cal = 0;
for (ll i = N; i >= 1; --i) {
cal -= x[i + 1] - x[i];
cal += v[i];
dp[1][i] = max(dp[1][i + 1], cal);
}
ll maxcal = 0;
for (ll i = 0; i <= N; ++i) {
cal = dp[0][i] + dp[1][i + 1] - x[i];
maxcal = max(maxcal, cal);
cal = dp[0][i] + dp[1][i + 1] - C + x[i + 1];
maxcal = max(maxcal, cal);
}
cout << maxcal << endl;
return 0;
}
```
21歳です。ゴミ記事を書きます
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away