結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-27 19:54:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 442 bytes |
| コンパイル時間 | 202 ms |
| コンパイル使用メモリ | 34,156 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-27 11:22:26 |
| 合計ジャッジ時間 | 809 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d%d",&n,&d);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d%d",&t[i],&k[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include<algorithm>
using namespace std;
int t[200], k[200];
int dp[200][2];
int main(void) {
int n,d;
scanf("%d%d",&n,&d);
for(int i=0; i<n; i++)
scanf("%d%d",&t[i],&k[i]);
dp[0][0] = 0;
dp[0][1] = -d;
for(int i=0; i<n; i++) {
dp[i+1][0] = max(dp[i][0], dp[i][1]-d) + t[i];
dp[i+1][1] = max(dp[i][1], dp[i][0]-d) + k[i];
}
printf("%d\n", max(dp[n][0], dp[n][1]));
}