#41634: easy solution prefix and suffix


jone921216@gmail.com (鍾帛勳)

學校 : 不指定學校
編號 : 143713
來源 : [111.246.73.31]
最後登入時間 :
2024-08-12 15:40:02
o079. 4. 最佳選擇 -- 2024年6月APCS | From: [111.246.73.31] | 發表日期 : 2024-08-12 16:04

Do the suffix first, then do the prefix. If sum of odd and even number amount of pref and suff are same and sum of pref + suff <= k, compare the answer.

While doing the prefix erase the suffix that index is smaller then current pointer or sum of pref and suff > k. O(N)

Or you can do then binary search to find the largest legal suffix. (O(NlogN))

 
ZeroJudge Forum