結果

問題 No.2408 Lakes and Fish
ユーザー milanis48663220milanis48663220
提出日時 2023-08-11 21:25:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,915 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 123,740 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-29 12:13:07
合計ジャッジ時間 3,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 77 ms
11,008 KB
testcase_05 AC 78 ms
11,008 KB
testcase_06 AC 79 ms
10,880 KB
testcase_07 AC 107 ms
11,008 KB
testcase_08 AC 106 ms
10,880 KB
testcase_09 AC 107 ms
11,008 KB
testcase_10 AC 107 ms
11,008 KB
testcase_11 AC 45 ms
6,400 KB
testcase_12 AC 74 ms
9,088 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 37 ms
6,016 KB
testcase_15 AC 77 ms
8,960 KB
testcase_16 AC 31 ms
6,400 KB
testcase_17 AC 18 ms
5,376 KB
testcase_18 AC 49 ms
7,552 KB
testcase_19 AC 67 ms
7,936 KB
testcase_20 AC 45 ms
5,632 KB
testcase_21 AC 73 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const ll inf = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<ll> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    vector<ll> f(m), b(m), w(m);
    for(int i = 0; i < m; i++) cin >> f[i] >> b[i] >> w[i];
    set<ll> st;
    for(int i = 0; i < n; i++) st.insert(l[i]);
    ll ans = 0;
    for(int i = 0; i < m; i++){
        auto p = st.lower_bound(f[i]);
        ll min_power = inf;
        if(p != st.end()){
            chmin(min_power, (*p)-f[i]);
        }
        if(p != st.begin()){
            p--;
            chmin(min_power, f[i]-(*p));
        }
        ans += max(b[i], w[i]-min_power);
    }
    cout << ans << endl;
}
0