結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
zeke
|
| 提出日時 | 2019-09-24 16:57:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,881 bytes |
| コンパイル時間 | 638 ms |
| コンパイル使用メモリ | 90,808 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-19 05:09:04 |
| 合計ジャッジ時間 | 1,404 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <limits>
using ll = long long;
using ld = long double;
int MOD = 1e9 + 7;
using namespace std;
struct UnionFind
{
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N)
{ //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int root(int x)
{ // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y)
{ // xとyの木を併合
int rx = root(x); //xの根をrx
int ry = root(y); //yの根をry
if (rx == ry)
return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y)
{ // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main()
{
ll n, d;
cin >> n >> d;
vector<vector<ll>> dp(n + 1, vector<ll>(2));
dp[0][0] = 0;
dp[0][1] = -d;
vector<vector<ll>> vec(n, vector<ll>(2));
for (int i = 0; i < n; i++)
{
ll t, k;
cin >> t >> k;
vec[i][0] = t;
vec[i][1] = k;
}
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 2; j++)
{
dp[i][j] = max(dp[i-1][1 - j] - d, dp[i-1][j]) + vec[i - 1][j];
}
}
cout << max(dp[n][0], dp[n][1]) << endl;
}
zeke