結果
問題 | No.2408 Lakes and Fish |
ユーザー |
![]() |
提出日時 | 2023-08-11 21:38:27 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 1,160 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 29,696 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 15:37:58 |
合計ジャッジ時間 | 2,184 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <stdio.h>int main () {int n = 0;int m = 0;int l[100000] = {};int f = 0;long long b = 0LL;long long w = 0LL;int res = 0;long long ans = 0LL;res = scanf("%d", &n);res = scanf("%d", &m);for (int i = 0; i < n; i++) {res = scanf("%d", l+i);}for (int i = 0; i < m; i++) {res = scanf("%d", &f);res = scanf("%lld", &b);res = scanf("%lld", &w);ans += b;if (f <= l[0] && w-((long long)(l[0]-f)) > b) {ans += w-((long long)(l[0]-f))-b;} else if (f >= l[n-1] && w-((long long)(f-l[n-1])) > b) {ans += w-((long long)(f-l[n-1]))-b;} else if (f > l[0] && f < l[n-1]) {int idx[2] = { 0, n-1 };while (idx[1]-idx[0] > 1) {int nxt = (idx[0]+idx[1])/2;if (l[nxt] < f) {idx[0] = nxt;} else {idx[1] = nxt;}}if (f-l[idx[0]] < l[idx[1]]-f && w-((long long)(f-l[idx[0]])) > b) {ans += w-((long long)(f-l[idx[0]]))-b;} else if (w-((long long)(l[idx[1]]-f)) > b) {ans += w-((long long)(l[idx[1]]-f))-b;}}}printf("%lld\n", ans);return 0;}