Page 3 of 4

Re: 11057 - Exact Sum

Posted: Fri Mar 22, 2013 12:04 am
by brianfry713
After each test case you must print a blank line.

Re: 11057 - Exact Sum

Posted: Sat Sep 28, 2013 10:47 pm
by The-PHx
why WA here ?!?
thanks in advance :))

Code: Select all

Accepted :D 

Re: 11057 - Exact Sum

Posted: Tue Oct 01, 2013 10:58 pm
by brianfry713
Input:

Code: Select all

2
40 40
80

5
10 2 6 8 4
10

4
4 6 2 8
10

3
1000000 100000 1
1100000
AC output:

Code: Select all

Peter should buy books whose prices are 40 and 40.

Peter should buy books whose prices are 4 and 6.

Peter should buy books whose prices are 4 and 6.

Peter should buy books whose prices are 100000 and 1000000.


Re: 11057 - Exact Sum

Posted: Sat Nov 23, 2013 12:27 pm
by ?????? ????

Code: Select all

Remove

Re: 11057 - Exact Sum

Posted: Tue Nov 26, 2013 11:09 pm
by brianfry713
Try input:

Code: Select all

3
1000000 1 1
2

Re: 11057 - Exact Sum

Posted: Sat Mar 15, 2014 10:43 pm
by TLEorWA
why WA? :(
help, here is my code:

http://pastebin.com/CM4rxcwq

i tried several inputs & outputs are ok,but still WA.

:(

Re: 11057 - Exact Sum

Posted: Mon Mar 17, 2014 11:17 pm
by brianfry713
Try input:

Code: Select all

6
40 40 1 79 39 41
80

Re: 11057 - Exact Sum

Posted: Fri May 09, 2014 2:06 am
by Mrsuit
I'm gettint WA, and it works for every input that i put.
Thank you.

Code: Select all

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;


public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String line;
int i=0;
int j=0;
//Clear the pp


while ((line=bf.readLine())!=null){ // i=test cases
	//list1= prices of the books
	//j= the amount of the sum
	i=Integer.parseInt(line);
	String[] list=new String[i];
	line=bf.readLine();
	list=line.split(" ");
	line=bf.readLine();
	j=Integer.parseInt(line);
	line=bf.readLine();
	int[] list2= new int [i];
	for (int k = 0; k < list.length; k++) {
		list2[k]=Integer.parseInt(list[k]);	
	}
	Arrays.sort(list2);
	
	//list2: numbers sorted 
	
	
	int min=0;
	int max=1000001;
	int f=0;
	int y=0;
	int x=0;
	for (int k2 = 0; k2 < list2.length; k2++) {
		for (int l = k2+1; l < list2.length; l++) {
			f=list2[k2]+list2[l];
			if (f==j){
				x=list2[k2];
				y=list2[l];
				if (Math.abs(min-max)>Math.abs(x-y)){
					min=x;
					max=y;
				}
				}
	}
	}
	if (max!=1000001){
		System.out.println("Peter should buy books whose prices are" +" " + min + " " + "and" +" " + max );
		System.out.println();
	}
	else {
		System.out.println("Peter should buy books whose prices are" +" " + 0 + " " + "and" +" " + 0);
		System.out.println();
	}
	
		
	pp.clear();
}
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
}

Re: 11057 - Exact Sum

Posted: Fri May 09, 2014 8:22 pm
by brianfry713
That code doesn't compile:
Main.java:66: error: cannot find symbol
pp.clear();
^
symbol: variable pp
location: class Main
1 error

You're also missing the . at the end of each line.

Re: 11057 - Exact Sum

Posted: Sat May 17, 2014 9:28 pm
by Mrsuit
brianfry713 wrote:That code doesn't compile:
Main.java:66: error: cannot find symbol
pp.clear();
^
symbol: variable pp
location: class Main
1 error

You're also missing the . at the end of each line.
I fixed thoses things, but i'm still getting WA.

Code: Select all

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;


public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String line;
StringBuilder sb = new StringBuilder();
int i=0;
int j=0;
while ((line=bf.readLine())!=null && !line.trim().equals("")){ // i=test cases
   //list1= prices of the books
   //j= the amount of the sum
   i=Integer.parseInt(line);
   String[] list=new String[i];
   line=bf.readLine();
   list=line.split(" ");
   line=bf.readLine();
   j=Integer.parseInt(line);
   line=bf.readLine();
   int[] list2= new int [i];
   for (int k = 0; k < list.length; k++) {
      list2[k]=Integer.parseInt(list[k]);   
   }
   Arrays.sort(list2);
   
   //list2: numbers sorted 
   
   
   int min=0;
   int max=1000001;
   int f=0;
   int y=0;
   int x=0;
   for (int k2 = 0; k2 < list2.length; k2++) {
      for (int l = k2+1; l < list2.length; l++) {
         f=list2[k2]+list2[l];
         if (f==j){
            x=list2[k2];
            y=list2[l];
            if (Math.abs(min-max)>Math.abs(x-y)){
               min=x;
               max=y;
            }
            }
   }
   }
   
   if (max!=1000001){
      sb.append("Peter should buy books whose prices are" +" " + min + " " + "and" +" " + max +"."+"\n\n" );
         }
   else {
      sb.append("Peter should buy books whose prices are" +" " + 0 + " " + "and" +" " + 0+"."+"\n\n");
     
   }
   
  }
System.out.println(sb.substring(0,sb.length()-2));
}
      
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

}

Re: 11057 - Exact Sum

Posted: Tue May 20, 2014 10:29 pm
by brianfry713
After each test case (including the last one) you must print a blank line.

Re: 11057 - Exact Sum

Posted: Wed May 21, 2014 6:07 am
by Mrsuit
brianfry713 wrote:After each test case (including the last one) you must print a blank line.

Lol, finally got AC, thank you so much! :)

Re: 11057 - Exact Sum

Posted: Wed Jun 11, 2014 1:51 pm
by uDebug
Don't forget to input the period (".") at the end of the sentence.

Re: 11057 - Exact Sum

Posted: Fri Aug 15, 2014 4:05 pm
by tausiftt5238

Code: Select all

#include <stdio.h>
#include <stdlib.h>
int compare(const void *a, const void *b)
{
	return ( *(int*)a - *(int*)b );
}
int main()
{
	int in[100000];
	int N,i,j,result,flag = 0;
	while(scanf("%d",&N)==1)
	{
		if(flag == 1)
			printf("\n");
		flag = 1;
		for(i=0;i<N;i++)
		{
			scanf("%d",&in[i]);
		}
		qsort(in,N,sizeof(int),compare);
		scanf("%d",&result);
		for(i=(N/2);i<N;i++)
		{
			for(j=i-1;j>=0;j--)
			{
				if(in[i]+in[j] == result)break;
			}
			if(in[i]+in[j] == result)break;
		}
		printf("Peter should buy books whose prices are %d and %d.\n",in[j],in[i]);
	}
	return 0;
}
got wa :\ i was expecting TLE..
anyway...
anyone have any idea why ?

Re: 11057 - Exact Sum

Posted: Fri Aug 15, 2014 11:56 pm
by lighted
After each test case you must print a blank line.
Try this

Code: Select all

5
1 2 3 4 5
3
got wa :\ i was expecting TLE..
It seems that judges input are weak. I changed two lines in your code and got accepted but it was wrong solution. :D
With current judge's input - solutions with O(N * N) is accepted. My solution is in O(N * logN)