Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sad story about Ruby, Python and (N == 10**5) problems... =/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- namespace scripts_are_not_good_enof
- {
- class JobDoneException: Exception { }
- class Pupil: IComparable {
- private static int encounter = 0;
- public int house, speed, id;
- public double reach_time;
- public bool lifted;
- public Pupil(int house, int speed){
- Pupil.encounter += 1;
- this.id += encounter;
- this.house = house;
- this.speed = speed;
- this.reach_time = (double)house/speed;
- this.lifted = false;
- }
- public double cur_pos(double time){
- return Math.Max(0, this.house - this.speed*time);
- }
- public int CompareTo(Object other){
- return (Math.Abs(this.reach_time - (other as Pupil).reach_time) < double.Epsilon) ? 0 :
- (this.reach_time > (other as Pupil).reach_time) ? -1 : 1;
- }
- }
- class Program
- {
- public static double time = 0;
- public static int our_speed;
- public static List<String> ans;
- public static List<Pupil> pupils;
- static String format_double(double n){
- var res = n.ToString().Replace(',', '.');
- if (res.IndexOf('.') == -1) res += ".0";
- return res;
- }
- static void DriveBy(Pupil pupil){
- // route to meet given pupil and lift him to the school
- double cur_pos = pupil.cur_pos(time);
- if (cur_pos < double.Epsilon || our_speed < pupil.speed)
- throw new JobDoneException();
- var closing_speed = our_speed + pupil.speed;
- ans.Add(String.Format("{0} {1}",
- pupil.id,
- format_double(cur_pos*our_speed/closing_speed)
- ));
- time += 2*cur_pos/closing_speed;
- pupil.lifted = true;
- }
- public static List<int> parse_int(String s){
- return s.Split().Select(x => int.Parse(x)).ToList();
- }
- public static void Main(string[] args)
- {
- /*
- var input = new StreamReader("in.txt");
- var output = new StreamWriter("out.txt");
- /*/
- var input = new StreamReader("race.in");
- var output = new StreamWriter("race.out");
- //*/
- ans = new List<String>();
- pupils = new List<Pupil>();
- var inp = parse_int(input.ReadLine());
- int n = inp[0]; our_speed = inp[1];
- for (int i = 0; i < n; i++){
- inp = parse_int(input.ReadLine());
- pupils.Add(new Pupil(inp[0], inp[1]));
- }
- pupils.Sort();
- try {
- for (int i = 0; i < pupils.Count(); i++) DriveBy(pupils[i]);
- } catch (JobDoneException) { }
- output.WriteLine(format_double(
- Math.Max(time,
- (pupils.Select(ppl => ppl.lifted ? 0 : ppl.reach_time).ToList().Max() ))
- ));
- output.WriteLine( ans.Count() );
- foreach (String line in ans) { output.WriteLine(line); }
- output.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment