// https://code.google.com/codejam/contest/8234486/dashboard#s=p1

// InputData -> solve is the method
// On UDebug the answer is coming more for some problem and for some it's 
coming less  

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor;

class B implements Runnable {
        String file = "B-large-practice";
        PrintWriter out;
        static boolean debug = true;
        static void preCalc(){}
        static class Source implements Comparable<Source>{
                double rate,temp;
                Source(double rate,double temp){
                        this.rate = rate;
                        this.temp = temp;
                }
                public int compareTo(Source that) {
                        return Double.compare(temp, that.temp);
                }
                
        }
        static class InputData{
                int N;
                double V,X;
                Source[] source;
                InputData(FastReader in) throws IOException{
                        N = in.nextInt();
                        V = in.nextDouble();
                        X = in.nextDouble();
                        source = new Source[N];
                        for(int i=0;i<N;i++){
                                source[i] = new 
Source(in.nextDouble(),Double.parseDouble(String.format("%.5f",in.nextDouble()-X)));
                        }
                }
                public String toString(){
                        return N+ " "+V+" "+X;
                }
                String solve(){
                        Arrays.sort(source);
                        double minX = source[0].temp;
                        double maxX = source[N-1].temp;
                        if(minX > 0 || maxX < 0) return "IMPOSSIBLE";
                        double score = 0;
                        for(int i=0;i<N;i++){ score += 
source[i].rate*source[i].temp; }
                        if(score >0){
                                for(int i=N-1;i>=0;i--){
                                        double current = 
source[i].rate*source[i].temp;
                                        if(current<=0) break;
                                        if(current>=score){
                                                source[i].rate = 
(current-score)/source[i].temp;
                                                break;
                                        }
                                        source[i].rate = 0;
                                        score-=current;
                                }
                        }else if (score < 0){
                                for(int i=0;i<N;i++){
                                        double current = 
source[i].rate*source[i].temp;
                                        if(current>=0) break;
                                        if(current<=score){
                                                source[i].rate 
=(current-score)/source[i].temp;
                                                break;
                                        }
                                        source[i].rate = 0;
                                        score-=current;
                                }
                        }
                        double rate = 0;
                        for(int i=0;i<N;i++){ rate += source[i].rate; }
                        V/=rate;
                        return String.format("%.9f", V);
                }
        }
        public void debug(){
                try {
                        FastReader in = new FastReader(new BufferedReader(new 
FileReader(file+".in")));
                        out = new PrintWriter(file + ".out");
                        for(int i=0,n = in.nextInt();i<n;i++){
                                InputData data = new InputData(in);
                                String s = data.solve();
                                System.out.println("Case #" + (i+1) + ": 
"+data.toString());
                                System.out.println("Case #" + (i+1) + ": "+s);
                                out.println("Case #" + (i + 1) + ": "+s);
                        }
                        out.close();
                } catch (FileNotFoundException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }
        public void run(){
                try {
                        FastReader in = new FastReader(new BufferedReader(new 
FileReader(file+".in")));
                        out = new PrintWriter(file + ".out");

                        ScheduledThreadPoolExecutor service = new 
ScheduledThreadPoolExecutor(16);

                        int tests = in.nextInt();
                        @SuppressWarnings("unchecked")
                        Future<String>[] ts = new Future[tests];
                        for (int test = 0; test < tests; ++test) {
                                ts[test] = service.submit(new Solver(new 
InputData(in)));
                        }
                        for (int test = 0; test < tests; ++test) {
                                while (!ts[test].isDone()) {
                                        Thread.sleep(500);
                                }
                                System.err.println("Test " + test);
                                out.print("Case #" + (test + 1) + ": ");
                                out.println(ts[test].get());
                        }
                        service.shutdown();

                        out.close();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
        static class Solver implements Callable<String>{
                InputData data;
                Solver(InputData data)  throws Exception{
                        this.data = data;
                }

                public String call() {
                        return data.solve();
                }
        }
        static class FastReader {
                public FastReader(BufferedReader in) {
                        this.in = in;
                        eat("");
                }

                private StringTokenizer st;
                private BufferedReader in;

                void eat(String s) {
                        st = new StringTokenizer(s);
                }

                String next() throws IOException {
                        while (!st.hasMoreTokens()) {
                                String line = in.readLine();
                                if (line == null) {
                                        return null;
                                }
                                eat(line);
                        }
                        return st.nextToken();
                }

                int nextInt() throws IOException {
                        return Integer.parseInt(next());
                }

                long nextLong() throws IOException {
                        return Long.parseLong(next());
                }

                double nextDouble() throws IOException {
                        return Double.parseDouble(next());
                }
        }
        public static void main(String[] args) {
                Locale.setDefault(Locale.US);
                long start = System.currentTimeMillis();
                preCalc();
                if(debug) new B().debug();
                else new B().run();
                System.err.println("Time taken : 
"+(System.currentTimeMillis()-start));
        }
}


// Thanks for going through

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/31faad44-dcd9-4e43-98f5-f048a9114769%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to