w0rm's blog

By w0rm, 16 years ago, In English
hi guys ,

i am trying to solve this practice problem at codechef .The only approach which i came upto is 
brute forcing which is giving me WA (due to overflows i guess ).
It would be helpful is you push me into right direction .

thanks

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

| Write comment?
16 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it
I see O(N^3)  solution - generate all possibles sums when for each sum check how much pairs it can give:


while (l < r) { if (x[l] + x[r] > s[i]) r--; else if (x[l] + x[r] < s[i]) l++; else { cur++, l++, r--; } }