Sum of pairsProblem code: PAIRSUM |
All submissions for this problem are available.
We call an array of integers X of size N good if it can be partitioned into 2 arrays of size n/2, say p1[] and p2[], such that p1[0] + p2[0] = p1[1] + p2[1] = p1[2] + p2[2] = ... . Given an array Y, determine the size of its largest subset which is a good array.
Input
The first line contains the integer N. The next line contains N space separated integers, which are the elements of the array X.
Output
One number which is the size of the greatest subset as mentioned in the problem statement.
Example
Input:
6
1 4 2 3 8 10
Output:
4
Explanation:
The array {1,4,2,3} is good, since you can form p1[] = {1,2} and p2[] = {4,3}. (satisfying 1 + 4 = 2 + 3)
| Author: | admin |
| Date Added: | 21-07-2009 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

How big can N be?
I assumed n=100 but it seems like constraints are much lower, looking at my Accepted time.
does the subset array has to be continuous ?
A subset by definition means that it need not be contiguous.
My code is working fine with expected results on my machine, but while submitting it fails with run time error - NZEC.
I have checked corner cases, but its not helping my cause.
This thing is really frustrating ..
any suggestions would be really helpful guys.
Thanks!
I read the tutorial on I/O and am taking good care of input format and output .. but still no success ...could somebody give me some pointers please ...
in the sample case you have given, is {1,4,2,3} the only possible subset..? I was saying {1,10,3,8} and {4,8,2,10} are also possible solutions...!
@shilpa There can be other possible subsets, but the size of each of them is 4.
can subset contain duplicated values?
No, all elements are distinct.
Find the longest arithmetic sequence
wat must be the o/p if i/p
wat must be the o/p if i/p is:-
5
1 23 45 97 213
???
i think it must be 2
because the max length of the array can be 2 because there is no equality case here.....
plz correct me if i m wrng ..thnx
yes got it AC thnx anyways
yes got it AC
thnx anyways
@gurpreet as i can see you
@gurpreet as i can see you got it AC... what should be the answer of your input case
5
1 23 45 97 213
should it be 2....
hey guys can i get more input cases.....
@gurpreet so should it be 2
@gurpreet so should it be 2
@admin i am freaking
@admin i am freaking out..
are u missing something that people are not able to make it because question is just simple one.
any condition something...
Can the input array contain
Can the input array contain duplicates?
can two loops work
can two loops work simultaneously?
is it necessary that the good
is it necessary that the good array's length shud be even??
@admin: u need to check the
@admin: u need to check the input and corresponding files. I think something is fishy.
Interesting problem this
Interesting problem this is...i liked it.
hello guys, i am finding sum
hello guys,
i am finding sum of every pair of numbers only 1 time , and storing d numbers of time every sum is obtained.
And displaying highest number of times * 2. I dont no where i am going wrong. Please help me with this.
Have you considered a case
Have you considered a case such as..
31 1 1
@Anoop... i think for the
@Anoop... i think for the test case stephen gave u wud be getting output 6 where as it shud be 2.. but stephen there is a comment by admin saying that the elements are distinct so is this test case valid... ????
admin was incorrect.
admin was incorrect.
ohh ... thanx ........ i
ohh ... thanx ........ i thought elements wll be disntinct ..
Hi, My code is working
Hi,
My code is working properly for the sample test case and also for other test cases, such as
3
1 1 1
output :2
but it is being considered as wrong when i submit it...so could anyone please suggest some test cases so that i can debug my code...
@Anoop ... even I am doing
@Anoop ... even I am doing the same but its giving me wrong answer :(
I resubmitted the same piece
I resubmitted the same piece of code judged wrong with differen compiler (g++ 4.0 instead of g++ 4.3) and my code works
My program runs perfectly on
My program runs perfectly on my machine, but here I see "run-time error". I do not see the specific error on the page. Memory used is fine, 1.6M, time taken is 0.00. There is no zero division involved. How can I see what exactly theerror is in this case ? I am new to this site. Thanks.
You could start by reading
You could start by reading the FAQ.
@Stephen Merriman The
@Stephen Merriman
The elements are distinct, as an accepted solution gives output "6" for "1 1 1"
That proves that '1 1 1' is
That proves that '1 1 1' is not a test case, not that the elements are always distinct.
can 2 4 5 3 3 can besplit