結果

問題 No.2408 Lakes and Fish
ユーザー Today03Today03
提出日時 2023-08-11 21:44:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 206,444 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-29 12:36:04
合計ジャッジ時間 4,202 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 49 ms
6,400 KB
testcase_05 AC 49 ms
6,400 KB
testcase_06 AC 49 ms
6,400 KB
testcase_07 AC 61 ms
6,400 KB
testcase_08 AC 63 ms
6,528 KB
testcase_09 AC 62 ms
6,272 KB
testcase_10 AC 61 ms
6,272 KB
testcase_11 AC 32 ms
5,376 KB
testcase_12 AC 45 ms
5,376 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 26 ms
5,376 KB
testcase_15 AC 50 ms
5,632 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 30 ms
5,376 KB
testcase_19 AC 47 ms
5,632 KB
testcase_20 AC 43 ms
5,504 KB
testcase_21 AC 49 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0