結果

問題 No.561 東京と京都
ユーザー HIR180HIR180
提出日時 2017-08-25 22:28:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 159,440 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 16:01:02
合計ジャッジ時間 2,291 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll dp[105][2],d,a[105],b[105];
int n;
int main(){
	cin >> n >> d;
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	rep(i,105)rep(j,2)dp[i][j]=-1e18;
	dp[0][0] = 0;
	for(int i=0;i<n;i++){
		if(dp[i][0]<0)goto nxt;
		dp[i+1][0] = max(dp[i+1][0],dp[i][0]+a[i]);
		dp[i+1][1] = max(dp[i+1][1],dp[i][0]+b[i]-d);
		nxt:;
		if(dp[i][1]<0)goto nxt2;
		dp[i+1][0] = max(dp[i+1][0],dp[i][1]+a[i]-d);
		dp[i+1][1] = max(dp[i+1][1],dp[i][1]+b[i]);
		nxt2:;
	}
	cout << max(dp[n][0],dp[n][1]) << endl;
}
0