結果

問題 No.2408 Lakes and Fish
ユーザー cho435cho435
提出日時 2023-08-11 23:16:17
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 204,984 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 18:35:42
合計ジャッジ時間 5,271 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> l(n);
	rep(i,n) cin>>l.at(i);
	vector<int> f(m),b(m),w(m);
	rep(i,m) cin>>f.at(i)>>b.at(i)>>w.at(i);
	ll ans=0;
	rep(i,m){
		if(!binary_search(l.begin(),l.end(),f.at(i))){
			auto itr=lower_bound(l.begin(),l.end(),f.at(i));
			int tmp=1e9;
			if(itr!=l.end()) tmp=min(tmp,*itr-f.at(i));
			if(itr!=l.begin()){
				itr--;
				tmp=min(tmp,f.at(i)-*itr);
			}
			ans+=max(b.at(i),w.at(i)-tmp);
		}else{
			ans+=w.at(i);
		}
	}
	cout<<ans<<endl;
}
0