結果

問題 No.2408 Lakes and Fish
ユーザー srjywrdnprkt
提出日時 2023-08-24 11:24:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 198,660 KB
最終ジャッジ日時 2025-02-16 13:00:46
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){

    ll N, M, ans=0, L;
    cin >> N >> M;
    set<ll> st;
    st.insert(1e18);
    st.insert(-1e18);
    for (int i=1; i<=N; i++){
        cin >> L;
        st.insert(L);
    }

    ll F, W, B;

    for (int i=0; i<M; i++){
        cin >> F >> B >> W;
        if (st.count(F)) ans += W;
        else{
            auto it = st.lower_bound(F);
            ll mi = *it-F;
            it--;
            mi = min(F-*it, mi);
            ans += max(W-mi, B);
        }
    }

    cout << ans << endl;

    return 0;
}
0