結果
問題 | No.2408 Lakes and Fish |
ユーザー |
![]() |
提出日時 | 2023-08-11 21:30:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 343 ms / 2,000 ms |
コード長 | 2,059 bytes |
コンパイル時間 | 3,301 ms |
コンパイル使用メモリ | 256,136 KB |
最終ジャッジ日時 | 2025-02-16 01:04:02 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include<bits/stdc++.h>using namespace std;//* ATCODER#include<atcoder/all>using namespace atcoder;typedef modint998244353 mint;//*//* BOOST MULTIPRECISION#include<boost/multiprecision/cpp_int.hpp>using namespace boost::multiprecision;//*/typedef long long ll;#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)template <typename T> bool chmin(T &a, const T &b) {if (a <= b) return false;a = b;return true;}template <typename T> bool chmax(T &a, const T &b) {if (a >= b) return false;a = b;return true;}template <typename T> T max(vector<T> &a){assert(!a.empty());T ret = a[0];for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);return ret;}template <typename T> T min(vector<T> &a){assert(!a.empty());T ret = a[0];for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);return ret;}template <typename T> T sum(vector<T> &a){T ret = 0;for (int i=0; i<(int)a.size(); i++) ret += a[i];return ret;}int main(){int n, m; cin >> n >> m;set<ll> sea;set<ll> groundt;rep(i,0,n){ll x; cin >> x;sea.insert(x);groundt.insert(x-1);groundt.insert(x+1);}set<ll> ground;for(auto v: groundt){if (sea.find(v) == sea.end()){ground.insert(v);}}ll ans = 0;rep(i,0,m){ll f, b, w; cin >> f >> b >> w;if (sea.find(f) != sea.end()){if (b <= w){ans += w;continue;}else{ll tmp = w;auto k = ground.lower_bound(f);if (k != ground.end()){ll val = *k;chmax(tmp, b - abs(val - f));}if (k != ground.begin()){k--;ll val = *k;chmax(tmp, b - abs(val - f));}ans += tmp;}}else{if (w <= b){ans += b;continue;}else{ll tmp = b;auto k = sea.lower_bound(f);if (k != sea.end()){ll val = *k;chmax(tmp, w - abs(val - f));}if (k != sea.begin()){k--;ll val = *k;chmax(tmp, w - abs(val - f));}ans += tmp;}}}cout << ans << '\n';}