結果

問題 No.2408 Lakes and Fish
ユーザー vjudge1vjudge1
提出日時 2024-05-01 23:02:46
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 6,495 ms
コンパイル使用メモリ 274,952 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 23:02:58
合計ジャッジ時間 8,563 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 57 ms
5,376 KB
testcase_05 AC 59 ms
5,376 KB
testcase_06 AC 56 ms
5,376 KB
testcase_07 AC 71 ms
5,376 KB
testcase_08 AC 71 ms
5,376 KB
testcase_09 AC 74 ms
5,376 KB
testcase_10 AC 72 ms
5,376 KB
testcase_11 AC 38 ms
5,376 KB
testcase_12 AC 50 ms
5,376 KB
testcase_13 AC 15 ms
5,376 KB
testcase_14 AC 30 ms
5,376 KB
testcase_15 AC 59 ms
5,376 KB
testcase_16 AC 20 ms
5,376 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 33 ms
5,376 KB
testcase_19 AC 55 ms
5,376 KB
testcase_20 AC 52 ms
5,376 KB
testcase_21 AC 58 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int Index(const vector<int>& sorted_vector, int n) {
    int low = 0;
    int high = sorted_vector.size() - 1;
    int closest_index = -1;
    
    while (low <= high) {
        int mid = (low + high) / 2;
        if (sorted_vector[mid] == n) {
            return mid;
        } else if (sorted_vector[mid] < n) {
            low = mid + 1;
        } else {
            high = mid - 1;
        }   
        if (closest_index == -1 || abs(sorted_vector[mid] - n) < abs(sorted_vector[closest_index] - n)) {
            closest_index = mid;
        }
    }
    return closest_index;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int pohon, ikan;
    cin>>pohon>>ikan;
    vector<int> phn;
    long long ans=0;
    for (int i=0; i<pohon; i++){
        int temp;
        cin>>temp;
        phn.push_back(temp);
    }
    
    for (int i=0; i<ikan; i++){
        int posisi, pow1, pow2;
        cin>>posisi>>pow1>>pow2;
        int selisih=pow2-pow1;
        int jarmin=abs(phn[Index(phn, posisi)]-posisi);
        if(jarmin<=selisih){
            ans+=(pow2-jarmin);
        } else ans+=pow1;
    }
    cout<<ans<<endl;
    return 0;
}
0