結果
| 問題 | No.2408 Lakes and Fish | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-10-27 16:01:22 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 193 ms / 2,000 ms | 
| コード長 | 802 bytes | 
| コンパイル時間 | 2,058 ms | 
| コンパイル使用メモリ | 194,960 KB | 
| 最終ジャッジ日時 | 2025-02-25 00:52:32 | 
| ジャッジサーバーID (参考情報) | judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i)
#define all(a) (a).begin(), (a).end()
int main() {
    cin.tie(nullptr);
    
    int N, M;
    cin >> N >> M;
    vector<ll> L(N), F(M), B(M), W(M);
    rep(i, 0, N) cin >> L[i];
    rep(i, 0, M) cin >> F[i] >> B[i] >> W[i];
    
    ll ans = 0;
    rep(i, 0, M) {
        if (binary_search(all(L), F[i])) {
            ans += W[i];
            continue;
        }
        
        int ind = lower_bound(all(L), F[i]) - L.begin();
        
        ll left = LLONG_MAX, right = LLONG_MAX;
        if (ind != N) right = L[ind] - F[i];
        if (ind != 0) left = F[i] - L[ind - 1];
        
        ans += max(B[i], W[i] - min(right, left));
    }
    cout << ans << '\n';
}
            
            
            
        