結果

問題 No.2408 Lakes and Fish
ユーザー vjudge1vjudge1
提出日時 2024-05-01 11:33:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,635 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 203,812 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 11:33:45
合計ジャッジ時間 4,260 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 47 ms
6,940 KB
testcase_05 AC 48 ms
6,944 KB
testcase_06 AC 52 ms
6,940 KB
testcase_07 AC 70 ms
6,940 KB
testcase_08 AC 69 ms
6,940 KB
testcase_09 AC 69 ms
6,944 KB
testcase_10 AC 69 ms
6,944 KB
testcase_11 AC 36 ms
6,940 KB
testcase_12 AC 49 ms
6,944 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 28 ms
6,940 KB
testcase_15 AC 55 ms
6,944 KB
testcase_16 AC 19 ms
6,944 KB
testcase_17 AC 16 ms
6,940 KB
testcase_18 AC 32 ms
6,944 KB
testcase_19 AC 52 ms
6,940 KB
testcase_20 AC 49 ms
6,944 KB
testcase_21 AC 54 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std; 
#define ld long double
#define fi first 
#define se second
#define int long long
#define pb push_back
const int mod = 1e9 + 7; 
vector<int>vis; 
int binser(int low, int high, int val){
    int l = low, r = high, ret = -1; 
    while(l <= r){
        int mid = (l+r)/2;
        if(vis[mid] <= val){
            ret = mid; l = mid + 1; 
        }
        else{
            r = mid - 1; 
        }
    }
    if(ret == -1)return ret; 
    else return val - vis[ret]; 
}
int binser2(int low, int high, int val){
    int l = low, r = high, ret = -1; 
    while(l <= r){
        int mid = (l+r)/2;
        if(vis[mid] >= val){
            ret = mid; r = mid - 1; 
        }
        else{
            l = mid + 1; 
        }
    }
    if(ret == -1)return ret; 
    else return vis[ret] - val; 
}
signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int n, m; cin >> n >> m; 
    
    for(int i = 1; i <= n; i++){
        int x; cin >> x; 
        vis.push_back(x);  
    }
    int ans = 0; 
    for(int i = 1; i <= m; i++){
        int f,b,w; cin >> f >> b >> w; 
        int tmp = binser(0,vis.size()-1,f), tmp2 = binser2(0,vis.size() - 1,f);
        //cout << "here >> " << tmp << " " << tmp2 << endl; 
        int val = -1; 
        if(tmp != -1){
            val = tmp; 
            if(tmp2 != -1)val = min(val,tmp2);
        }
        else if(tmp2 != -1)val = tmp2; 
        //cout << "here >> " << val << endl; 
        if(val == -1 || w - val <= b){
            ans += b; 
        }
        else{
            ans += (w - val); 
        }
    }
    cout << ans; 
}
0