結果

問題 No.2408 Lakes and Fish
ユーザー vjudge1vjudge1
提出日時 2024-05-02 00:43:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 2,588 bytes
コンパイル時間 2,906 ms
コンパイル使用メモリ 251,944 KB
実行使用メモリ 387,172 KB
最終ジャッジ日時 2024-05-02 00:43:28
合計ジャッジ時間 7,906 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,940 KB
testcase_04 AC 58 ms
6,944 KB
testcase_05 AC 58 ms
6,944 KB
testcase_06 AC 43 ms
6,944 KB
testcase_07 AC 344 ms
385,488 KB
testcase_08 AC 356 ms
387,172 KB
testcase_09 AC 347 ms
386,960 KB
testcase_10 AC 361 ms
386,456 KB
testcase_11 AC 184 ms
199,032 KB
testcase_12 AC 273 ms
331,044 KB
testcase_13 AC 107 ms
172,364 KB
testcase_14 AC 168 ms
204,532 KB
testcase_15 AC 274 ms
302,256 KB
testcase_16 AC 168 ms
249,236 KB
testcase_17 AC 98 ms
141,900 KB
testcase_18 AC 217 ms
289,800 KB
testcase_19 AC 248 ms
251,644 KB
testcase_20 AC 167 ms
93,416 KB
testcase_21 AC 260 ms
270,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#define fi first
#define se second
const int MOD = 1e9+7;
#define pin pair<int,int>
#define lup(i,x) for(int i=0; i<x; i++)
#define pb push_back
#define pu push
#define vint vector<int>
#define nitro ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define din(x) int x;cin>>x;
#define endl '\n'
#define cout std::cout
const int maxn = 1e9+5;
bool ar[maxn];
vector<int> po;

int bin(int tar, int left, int right){
     int l = left;
     int r = right;
     int mid;
     int ans = -1;
     while(l<=r){
          mid = (l+r)/2;
          if(po[mid]<tar){
               l = mid+1;
          }else if(po[mid] > tar){
               r = mid-1;
               ans = po[mid];
          }
     }
     return ans;
}
int bin2(int tar, int left, int right){
     // cout << "  tar" << left << " " << right << endl;
     int l = left;
     int r = right;
     int mid;
     int ans = -1;
     while(l<=r){
          // cout << "  "<< l <<" "<<r << endl;
          mid = (l+r)/2;
          if(po[mid]>tar){
               r = mid-1;
          }else if(po[mid] < tar){
               l = mid+1;
               ans = po[mid];
          }
     }
     // cout << "  "<<ans << endl;
     return ans;
}

void solve(){
     int n, m;
     cin >> n >> m;
     
     for(int i = 0; i < n; i++){
          int a; cin >> a;
          po.pb(a);
          ar[a] = true;
     }
     sort(po.begin(), po.end());
     
     // for(auto n : po) cout << n << " ";
     int sum = 0;
     for(int i = 0; i < m; i++ ){
          int f, b, w;
          cin >> f >> b >> w;
          if(ar[f]==true){
               sum += w;
          }else{
               int ma = 1e11;
               int kanan = bin(f, 0, n-1);
               if(kanan!=-1) ma = min(ma,kanan-f);
               // cout << f << endl;
               // cout << "  kan "<< kanan << endl;
               int kiri = bin2(f, 0, n-1);
               // cout << "  kir "<<kiri << endl;
               if(kiri!=-1) ma = min(ma,f-kiri);
               
               // cout << ma << endl;
               if(ma==1e11){
                    sum+=b;
               }else{
                    if(b < w-ma){
                         sum += w-ma;
                    }else{
                         sum += b;
                    }
               }
          }
     }
     cout << sum << endl;
}

signed main(){
     nitro
     // int n;
     // cin >> n;
     // while(n--){
          solve();
     // }
}
0