×

# Not a triangle

 0 I am getting WA for the question:http://www.codechef.com/problems/NOTATRI/ Anyone plz. explain where i am wrong.Thnx. My code: http://www.codechef.com/viewsolution/2213497 asked 09 Jun '13, 11:49 2★fiery 190●9●11●17 accept rate: 0%

 0 sorting will help in terms of time. after sorting, start from the greatest value of length, if sum of smallest value and value lesser than(l[k-1]) taken value(l[k]), then add difference to count(cnt=cnt+l[k-1]-l[i]), because sum of all indices between those numbers, if considered particularly, will be lesser than taken value(l[k]). if sum of those two particular indices is greater than or equal to taken value(l[i]+l[j]>=l[k]), then increment the smallest index(i++). loop the aforementioned case for all index. voila. answered 05 Jan '14, 08:35 1★garakchy 1.1k●16●30●48 accept rate: 1%
 0 1.What we will be doing is , we will take a set of 3 lengths say {first,second,third} such that first<=second<=third. This way we will count only unique sets. 2.After this we will fix first=0 and third = n-1 , i.e first and last elements of sorted array.Yes , array has to be sorted . Quick sort or Merge sort can be used. 3.Now loop is on third = n-1 to 0. for each chosen third , i have inner loop on first. 4.Now second begins from third-1 and move towards first. Now if we find some second such that first + second < third then our condition is satisfied and all such numbers between first and second are suitable candidates for "second". hence we count their number and add them. For a better understanding of solution look here answered 16 May '14, 21:11 355●8●19 accept rate: 20%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×558

question asked: 09 Jun '13, 11:49

question was seen: 2,180 times

last updated: 16 May '14, 21:18