0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 21:28:48 +00:00

D - Snuke Panic (1D)

https://atcoder.jp/contests/abc266/submissions/34405932
This commit is contained in:
Baoshuo Ren 2022-08-27 21:46:42 +08:00
parent d47e857941
commit b3589241ce
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

60
AtCoder/ABC266/D/D.cpp Normal file
View File

@ -0,0 +1,60 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <limits>
#include <utility>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, min_t, max_t;
std::array<long long, 5> f[N];
std::array<std::pair<int, int>, N> snukes;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
min_t = std::numeric_limits<int>::max();
max_t = std::numeric_limits<int>::min();
std::fill(snukes.begin(), snukes.end(), std::make_pair(-1, 0));
for (int i = 1, t, x, a; i <= n; i++) {
cin >> t >> x >> a;
snukes[t] = std::make_pair(x, a);
min_t = std::min(min_t, t);
max_t = std::max(max_t, t);
}
f[0][1] = f[0][2] = f[0][3] = f[0][4]
= f[1][1] = f[1][2] = f[1][3] = f[1][4]
= f[2][2] = f[2][3] = f[2][4]
= f[3][3] = f[3][4]
= std::numeric_limits<long long>::min();
for (int i = 1; i <= max_t; i++) {
std::copy_n(f[i - 1].begin(), std::min(i, 5), f[i].begin());
if (snukes[i].first == -1) continue;
long long x = std::numeric_limits<long long>::min();
for (int j = 0; j <= 4; j++) {
if (i - std::abs(j - snukes[i].first) < 0) continue;
x = std::max(x, f[i - std::abs(j - snukes[i].first)][j] + snukes[i].second);
}
f[i][snukes[i].first] = std::max(f[i][snukes[i].first], x);
}
cout << std::max({f[max_t][0], f[max_t][1], f[max_t][2], f[max_t][3], f[max_t][4]}) << endl;
return 0;
}