A car moves with a speed of v, but speedo shows speed v+k. Find k↵
↵
The first line of the input contains two integers: n (1 ≤ n ≤ 1000), which represents the number of parts of the trip, and the number t (1 ≤ t ≤ 10 ^ 6), which represents the total trip time. Below are n lines, each of which describes one part of the trip. Each line contains two integers: s (1 ≤ s ≤ 1000) and v (|v| ≤ 1000) — distance and speed.↵
↵
Example input:↵
↵
~~~~~↵
4 10↵
↵
5 3↵
2 2↵
3 6↵
3 1↵
~~~~~↵
↵
↵
Output:↵
-0.508653377↵
↵
My solution:↵
↵
↵
~~~~~↵
int n,t;↵
scanf("%d%d",&n,&t);↵
double full_distance = 0, full_speed = 0;↵
~~~~~↵
↵
↵
↵
~~~~~↵
for ( int i = 0; i < n; i++ )↵
{↵
int s,v;↵
scanf("%d%d",&s,&v);↵
total_distance += s;↵
total_speed += v;↵
}↵
~~~~~↵
↵
↵
↵
~~~~~↵
double invalid_speed = total_speed/n; average speed(v+k) for one part of the trip↵
double valid_speed = total_distance/(double)t; ( v = s/t( speed that the car should have been )`↵
double result = correct_speed-fake_speed;↵
printf("%.9f\n",result);↵
~~~~~↵
↵
↵
↵
↵
The first line of the input contains two integers: n (1 ≤ n ≤ 1000), which represents the number of parts of the trip, and the number t (1 ≤ t ≤ 10 ^ 6), which represents the total trip time. Below are n lines, each of which describes one part of the trip. Each line contains two integers: s (1 ≤ s ≤ 1000) and v (|v| ≤ 1000) — distance and speed.↵
↵
Example input:↵
↵
~~~~~↵
4 10↵
↵
5 3↵
2 2↵
3 6↵
3 1↵
~~~~~↵
↵
↵
Output:↵
-0.508653377↵
↵
My solution:↵
↵
↵
~~~~~↵
int n,t;↵
scanf("%d%d",&n,&t);↵
double full_distance = 0, full_speed = 0;↵
~~~~~↵
↵
↵
↵
~~~~~↵
for ( int i = 0; i < n; i++ )↵
{↵
int s,v;↵
scanf("%d%d",&s,&v);↵
total_distance += s;↵
total_speed += v;↵
}↵
~~~~~↵
↵
↵
↵
~~~~~↵
double invalid_speed = total_speed/n; average speed(v+k) for one part of the trip↵
double valid_speed = total_distance/(double)t; ( v = s/t
double result = correct_speed-fake_speed;↵
printf("%.9f\n",result);↵
~~~~~↵
↵
↵
↵