結果

問題 No.2408 Lakes and Fish
ユーザー vjudge1
提出日時 2024-05-01 22:51:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 195,664 KB
最終ジャッジ日時 2025-02-21 10:05:42
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
#include <cctype>
using namespace std; 

#define fi first
#define se second
#define int long long
#define all(v) v.begin(), v.end()
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
//iota(first, last, 1);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<string, ii> sii;
typedef pair<int, ii> iii;

const int INF = 3e18;
const long double EPS = 10e-9;
const ll MOD = 1e9+7;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n, m; cin >> n >> m;	
	vector<int> l;
	for (int i=1; i<=n; i++) {
		int a; cin >> a; l.pb(a);
	}
	int ans = 0;
	for (int i=1; i<=m; i++) {
		int f, b, w; cin >> f >> b >> w;
		int x = b; 
		auto itr = lower_bound(l.begin(), l.end(), f);
		if (itr != l.end()) {
			x = max(x, w - abs(f - *itr));
			// c << *itr << " " << f << '\n';
		} 
		if (itr != l.begin()) {
			x = max(x, w - abs(f - *(--itr)));
		} 
		// cout << *itr << " " << f << '\n';
		ans += x;
	} cout << ans;
	return 0;
} 
0