結果

問題 No.2408 Lakes and Fish
ユーザー PAKACHUPAKACHU
提出日時 2023-08-11 21:57:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 2,483 ms
コンパイル使用メモリ 164,028 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 12:52:50
合計ジャッジ時間 5,718 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 155 ms
5,376 KB
testcase_05 AC 157 ms
5,376 KB
testcase_06 AC 147 ms
5,376 KB
testcase_07 AC 166 ms
5,376 KB
testcase_08 AC 167 ms
5,376 KB
testcase_09 AC 166 ms
5,376 KB
testcase_10 AC 166 ms
5,376 KB
testcase_11 AC 87 ms
5,376 KB
testcase_12 AC 119 ms
5,376 KB
testcase_13 AC 34 ms
5,376 KB
testcase_14 AC 69 ms
5,376 KB
testcase_15 AC 136 ms
5,376 KB
testcase_16 AC 48 ms
5,376 KB
testcase_17 AC 38 ms
5,376 KB
testcase_18 AC 81 ms
5,376 KB
testcase_19 AC 127 ms
5,376 KB
testcase_20 AC 125 ms
5,376 KB
testcase_21 AC 133 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const long long mod = 998244353;
const ll inf = 1LL << 60;
const int INF = 5e8;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
        cin >> l[i];

    ll ans = 0;
    for (int i = 0; i < m; i++) {
        int f, b, w;
        cin >> f >> b >> w;
        auto it = lower_bound(l.begin(), l.end(), f);
        if (it == l.begin()) {
            ans += max(b, -(l[0] - f) + w);
        } else if (it == l.end()) {
            ans += max(b, -(f - l[n - 1]) + w);
        } else {
            ans += max({ b, -(*it - f) + w, -(f - *prev(it)) + w });
        }
    }
    cout << ans << endl;
}
0