結果

問題 No.2408 Lakes and Fish
ユーザー shobonvipshobonvip
提出日時 2023-08-11 21:30:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 2,059 bytes
コンパイル時間 4,694 ms
コンパイル使用メモリ 267,216 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-04-29 12:20:09
合計ジャッジ時間 10,402 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 254 ms
12,800 KB
testcase_05 AC 254 ms
12,800 KB
testcase_06 AC 252 ms
12,800 KB
testcase_07 AC 418 ms
26,880 KB
testcase_08 AC 406 ms
26,880 KB
testcase_09 AC 413 ms
26,880 KB
testcase_10 AC 419 ms
26,880 KB
testcase_11 AC 162 ms
11,264 KB
testcase_12 AC 299 ms
22,144 KB
testcase_13 AC 77 ms
9,472 KB
testcase_14 AC 143 ms
11,776 KB
testcase_15 AC 308 ms
19,456 KB
testcase_16 AC 142 ms
15,232 KB
testcase_17 AC 66 ms
7,296 KB
testcase_18 AC 209 ms
18,432 KB
testcase_19 AC 251 ms
15,360 KB
testcase_20 AC 142 ms
5,376 KB
testcase_21 AC 269 ms
16,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}

0