結果

問題 No.818 Dinner time
ユーザー lapilapi
提出日時 2019-04-20 20:31:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,155 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 102,700 KB
実行使用メモリ 7,520 KB
最終ジャッジ日時 2024-04-09 21:10:41
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 1 ms
6,940 KB
testcase_11 WA -
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 19 ms
7,520 KB
testcase_18 AC 14 ms
6,944 KB
testcase_19 AC 14 ms
6,948 KB
testcase_20 AC 18 ms
7,268 KB
testcase_21 AC 17 ms
7,084 KB
testcase_22 AC 13 ms
6,948 KB
testcase_23 AC 16 ms
7,012 KB
testcase_24 AC 21 ms
7,392 KB
testcase_25 AC 15 ms
6,940 KB
testcase_26 AC 13 ms
6,944 KB
testcase_27 AC 19 ms
7,040 KB
testcase_28 AC 17 ms
7,008 KB
testcase_29 AC 21 ms
7,268 KB
testcase_30 AC 17 ms
6,940 KB
testcase_31 AC 19 ms
7,144 KB
testcase_32 AC 16 ms
7,012 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] * l, A[n] * (l - 1) + B[n]);
	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[0][0] = dp[0][1] = dp[0][2] = 0;
	for (int i = 1; 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