Codeforces will not be available in the period 01:00-05:00 May, 30 (MSK, UTC +3) because of maintenance. ×

### SaSoriSaYOra's blog

By SaSoriSaYOra, history, 2 months ago, ,

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);
`

• 0

 » 2 months ago, # |   0 Why I'm getting wrong output
•  » » 2 months ago, # ^ |   0 how can the output be negative? k should be +ve
 » 2 months ago, # |   0 Auto comment: topic has been updated by SaSoriSaYOra (previous revision, new revision, compare).
 » 2 months ago, # |   0 The total speed(V) isn't the sum of all speeds.From s(distance)=v(speed)*t(time), we get that D(the total distance) is equal to $v_1t_1+v_2t_2+...+vn*tn$.t=s/v.The average speed is $V=\frac{D}{\sum t}$.The answer is V-k.