結果
| 問題 | No.2408 Lakes and Fish | 
| コンテスト | |
| ユーザー |  vjudge1 | 
| 提出日時 | 2024-05-01 23:02:46 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 72 ms / 2,000 ms | 
| コード長 | 1,218 bytes | 
| コンパイル時間 | 3,474 ms | 
| コンパイル使用メモリ | 275,008 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-22 06:50:14 | 
| 合計ジャッジ時間 | 5,737 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 | 
ソースコード
#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;
}
            
            
            
        