結果
| 問題 | No.2408 Lakes and Fish | 
| コンテスト | |
| ユーザー |  Today03 | 
| 提出日時 | 2023-08-11 21:44:12 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 64 ms / 2,000 ms | 
| コード長 | 700 bytes | 
| コンパイル時間 | 2,180 ms | 
| コンパイル使用メモリ | 198,504 KB | 
| 最終ジャッジ日時 | 2025-02-16 01:13:37 | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<long long> l(n),f(m),b(m),w(m);
  for (int i=0;i<n;i++) cin>>l[i];
  for (int i=0;i<m;i++) cin>>f[i]>>b[i]>>w[i];
  sort(l.begin(),l.end());
  long long ans=0;
  for (int i=0;i<m;i++) {
    int idx=lower_bound(l.begin(),l.end(),f[i])-l.begin();
    if (idx==n) idx--;
    if (l[idx]==f[i]) {
      ans+=w[i];
      continue;
    }
    long long res=b[i];
    long long get=w[i]-abs(l[idx]-f[i]);
    res=max(res,get);    
    if (idx>0) {
      idx--;
      long long get2=w[i]-abs(f[i]-l[idx]);
      res=max(res,get2);
    }
    ans+=res;
  }
  cout<<ans<<endl;
}
            
            
            
        