結果

問題 No.818 Dinner time
ユーザー lapilapi
提出日時 2019-04-20 22:40:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 102,288 KB
実行使用メモリ 7,044 KB
最終ジャッジ日時 2023-08-20 00:58:15
合計ジャッジ時間 2,513 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 20 ms
7,036 KB
testcase_18 AC 14 ms
5,748 KB
testcase_19 AC 15 ms
5,960 KB
testcase_20 AC 19 ms
6,816 KB
testcase_21 AC 18 ms
6,328 KB
testcase_22 AC 14 ms
5,640 KB
testcase_23 AC 16 ms
6,180 KB
testcase_24 AC 23 ms
7,044 KB
testcase_25 AC 16 ms
5,872 KB
testcase_26 AC 13 ms
5,456 KB
testcase_27 AC 20 ms
6,716 KB
testcase_28 AC 16 ms
6,208 KB
testcase_29 AC 21 ms
6,788 KB
testcase_30 AC 18 ms
6,536 KB
testcase_31 AC 20 ms
6,568 KB
testcase_32 AC 16 ms
6,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

ll A[100001];
ll B[100001];

ll dp[100001][3]; // dp[i][0] : i番目の鶏を0回使う時の最大
				  // dp[i][1] : i番目の鶏を1回使う時の最大
				  // dp[i][2] : i番目の鶏をM回使う時の最大

ll f(int n, int l) {
	ll res = max(A[n], B[n]) + A[n] * (l - 1);
	res = max(res, ll(B[n]));
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M; cin >> N >> M;

	for (int i = 1; i <= N; i++) cin >> A[i] >> B[i];

	dp[1][0] = -INF;
	dp[1][1] = -INF;
	dp[1][2] = f(1, M);

	for (int i = 2; i <= N; i++) {
		dp[i][2] = dp[i - 1][2] + f(i, M);
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][1]) + f(i, 1);
		dp[i][0] = max(dp[i - 1][2], max(dp[i - 1][1], dp[i - 1][0]));
	}

	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;

	return 0;
}
0