結果

問題 No.2408 Lakes and Fish
ユーザー daiotadaiota
提出日時 2023-08-11 23:10:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 3,668 ms
コンパイル使用メモリ 169,492 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-29 14:20:27
合計ジャッジ時間 3,396 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 1 ms
5,376 KB
testcase_04 AC 44 ms
6,272 KB
testcase_05 AC 42 ms
6,400 KB
testcase_06 AC 44 ms
6,400 KB
testcase_07 AC 55 ms
6,400 KB
testcase_08 AC 55 ms
6,272 KB
testcase_09 AC 59 ms
6,400 KB
testcase_10 AC 59 ms
6,272 KB
testcase_11 AC 29 ms
5,376 KB
testcase_12 AC 37 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 21 ms
5,376 KB
testcase_15 AC 41 ms
5,760 KB
testcase_16 AC 15 ms
5,376 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 AC 40 ms
5,760 KB
testcase_20 AC 38 ms
5,760 KB
testcase_21 AC 40 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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