Nathan Coulas

CCC '20 S1 - Surmising a Sprinter's Speed

ccc20s1 CPP17 22 Apr, 2020 0.571s 3 points

Source Code

#include <bits/stdc++.h>
#include <iostream>
#include <stdlib.h>

using namespace std;


void pairsort(double a[], double b[], int n) 
{ 
    pair<double, double> pairt[n]; 
  
    for (int i = 0; i < n; i++)  
    { 
        pairt[i].first = a[i]; 
        pairt[i].second = b[i]; 
    } 
  
    sort(pairt, pairt + n); 
       
    for (int i = 0; i < n; i++)  
    { 
        a[i] = pairt[i].first; 
        b[i] = pairt[i].second; 
    } 
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	double temp, best = 0; 
	cin >> n; 
	double times[n] = {0};
	double locations[n] = {0};
	
	for(int i = 0; i < n; i++){
		cin >> times[i] >> locations[i];
	}
	
	pairsort(times, locations, sizeof(times) / sizeof(times[0]));
	
	for(int i = 1; i < n; i++){
		temp = abs(locations[i] - locations[i - 1]) / (times[i] - times[i - 1]);
		if(temp > best){
			best = temp;
		}
	
	}
	
	cout << fixed << setprecision(5) << best;
		return 0;
	}