結果

問題 No.561 東京と京都
ユーザー jimmyo0705jimmyo0705
提出日時 2018-09-25 14:00:47
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,657 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 90,420 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-04 10:29:48
合計ジャッジ時間 1,414 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,d;
ll t[100],k[100];

ll dp[101][2];

int main(){
	cin >> n >> d;
	rep(i,n)cin >> t[i] >> k[i];
	rep(i,n){
		if(i == 0){
			dp[i+1][0] = dp[i][0] + t[i];
			dp[i+1][1] = dp[i][0] + k[i] - d;
		}
		else{
			dp[i+1][0] = max(dp[i][0] + t[i],dp[i][1] + t[i] - d);
			dp[i+1][1] = max(dp[i][1] + k[i],dp[i][0] + k[i] - d);
		}
	}
	cout << max(dp[n][0],dp[n][1]) << endl;
}
0