Блог пользователя w0rm

Автор w0rm, 14 лет назад, По-английски
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

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

14 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится
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--; } }