結果

問題 No.561 東京と京都
ユーザー fura
提出日時 2020-05-04 18:22:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 436 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 191,280 KB
最終ジャッジ日時 2025-01-10 06:26:35
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         int n,d; scanf("%d%d",&n,&d);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:17:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                 int t,k; scanf("%d%d",&t,&k);
      |                          ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int main(){
	int n,d; scanf("%d%d",&n,&d);

	lint dp[101][2];
	rep(i,n+1) rep(j,2) dp[i][j]=-INF;
	dp[0][0]=0;
	rep(i,n){
		int t,k; scanf("%d%d",&t,&k);
		dp[i+1][0]=max(dp[i][0],dp[i][1]-d)+t;
		dp[i+1][1]=max(dp[i][0]-d,dp[i][1])+k;
	}
	printf("%lld\n",max(dp[n][0],dp[n][1]));

	return 0;
}
0