結果
問題 | No.2408 Lakes and Fish |
ユーザー |
|
提出日時 | 2023-08-11 23:10:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 984 bytes |
コンパイル時間 | 1,470 ms |
コンパイル使用メモリ | 171,056 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 18:27:41 |
合計ジャッジ時間 | 3,335 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;#define REP(i,n) for(int i=0;i<int(n);i++)ll F[100010],B[100010],W[100010];int main(void){cin.tie(nullptr); ios_base::sync_with_stdio(false);ll i,j,k;ll N,M;cin >> N >> M;vector<ll> L(N);for(i=0;i<N;i++){cin >> L[i];}for(i=1;i<=M;i++){cin >> F[i] >> B[i] >> W[i];}ll ans=0;for(i=1;i<=M;i++){ll x=lower_bound(L.begin(),L.end(),F[i])-L.begin();if(F[i]==L[x]){ans+=W[i];continue;}if(x==0){if(L[0]-F[i]>=W[i]-B[i]){ans+=B[i];continue;}else{ans+=W[i]-(L[0]-F[i]);continue;}}if(x==N){if(F[i]-L[N-1]>=W[i]-B[i]){ans+=B[i];continue;}else{ans+=W[i]-F[i]+L[N-1];continue;}}if(L[x]-F[i]<W[i]-B[i] || F[i]-L[x-1]<W[i]-B[i]){ans+=B[i]+max(W[i]-B[i]-L[x]+F[i],W[i]-B[i]-F[i]+L[x-1]);}else{ans+=B[i];}}cout << ans << endl;return 0;}