結果

問題 No.2408 Lakes and Fish
ユーザー AnchorBluesAnchorBlues
提出日時 2023-09-23 13:13:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,592 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 204,864 KB
実行使用メモリ 4,724 KB
最終ジャッジ日時 2023-09-23 13:13:27
合計ジャッジ時間 6,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 54 ms
4,544 KB
testcase_05 AC 55 ms
4,724 KB
testcase_06 AC 56 ms
4,664 KB
testcase_07 AC 69 ms
4,684 KB
testcase_08 AC 70 ms
4,556 KB
testcase_09 AC 70 ms
4,684 KB
testcase_10 AC 72 ms
4,664 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 47 ms
4,460 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 29 ms
4,380 KB
testcase_15 AC 54 ms
4,376 KB
testcase_16 AC 21 ms
4,376 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 34 ms
4,380 KB
testcase_19 AC 49 ms
4,384 KB
testcase_20 AC 45 ms
4,380 KB
testcase_21 AC 53 ms
4,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll INF = 1LL << 60;

template <class T>
void chmax(T& a, T b) {
    if (b > a) a = b;
}
template <class T>
void chmin(T& a, T b) {
    if (b < a) a = b;
}

template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept {
    return os << "(" << x.first << ", " << x.second << ")";
}

template <typename T>
void print_vector(vector<T> a) {
    cout << '[';
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i != a.size() - 1) {
            cout << ", ";
        }
    }
    cout << ']' << endl;
}

void solve() {
    ll N, M;
    cin >> N >> M;
    vector<ll> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    L.push_back(INF);
    L.push_back(-INF);
    sort(L.begin(), L.end());
    ll ret = 0;
    for (int j = 0; j < M; j++) {
        ll f, b, w;
        cin >> f >> b >> w;
        auto it = lower_bound(L.begin(), L.end(), f);
        if (*it == f) {
            // もともと水中にいる
            ret += w;
            continue;
        }
        ll x = *prev(it);
        ll y = *it;
        ll z = min(y - f, f - x);
        ret += max(w - z, b);
    }
    std::cout << ret << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}
0