Negationist's blog

By Negationist, history, 2 years ago, In English

Problem: Array Game — https://codeforces.me/contest/1904/problem/C Idea of the code, consider all possible combinations of 2 elements to make diff, mn = min of, mn, diff, [first element greater than diff]-diff, [one element left of the first element greater than diff]-diff. Thanks so much.

My Code
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my man k==2 case will get you to a nice n^2 TLE you must use binary search for each difference

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

at k==2 for(int i=0; i<n-1;i++) You put i<n-2, so you skipped one check

Try a=[5,98,99], ans is 1, but you get 4 because 98-(99-5)=4