結果

問題 No.2408 Lakes and Fish
ユーザー vjudge1vjudge1
提出日時 2024-05-02 00:43:50
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 4,951 ms
コンパイル使用メモリ 124,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 00:43:59
合計ジャッジ時間 5,465 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 165 ms
5,376 KB
testcase_05 AC 164 ms
5,376 KB
testcase_06 AC 156 ms
5,376 KB
testcase_07 AC 182 ms
5,376 KB
testcase_08 AC 185 ms
5,376 KB
testcase_09 AC 185 ms
5,376 KB
testcase_10 AC 185 ms
5,376 KB
testcase_11 AC 94 ms
5,376 KB
testcase_12 AC 129 ms
5,376 KB
testcase_13 AC 36 ms
5,376 KB
testcase_14 AC 75 ms
5,376 KB
testcase_15 AC 145 ms
5,376 KB
testcase_16 AC 52 ms
5,376 KB
testcase_17 AC 41 ms
5,376 KB
testcase_18 AC 87 ms
5,376 KB
testcase_19 AC 140 ms
5,376 KB
testcase_20 AC 135 ms
5,376 KB
testcase_21 AC 143 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <vector>
#include <cmath>
#include <set>
#define ll long long
using namespace std;

int main() {
    ll n, m;
    cin >> n >> m; 

    vector<int> pohon(n);
    for (int i = 0; i < n; i++) cin >> pohon[i];

    ll score = 0;
    for (int i = 0; i < m; i++)
    {
        ll f, b, w;
        cin >> f >> b >> w;

        ll ansdist = 1e9 + 7;
        ll l = 0, r = n-1;
        while (l <= r)
        {
            int mid = l + (r - l) / 2;

            ll dist = pohon[mid] - f;

            if (abs(dist) <= ansdist)
                ansdist = abs(dist);
            
            if (dist == 0)
            {
                ansdist = 0;
                break;
            } else if (dist < 0)
            {
                l = mid + 1;
            } else if (dist > 0)
            {
                r = mid - 1;
            }
        }

        ll profit = w - b;
        if (profit > ansdist)
        {
            score += (w - ansdist);
        } else score += b;
    }
    
    cout << score << endl;
    return 0;
}
0