Solution for CCC '20 S1 - Surmising a Sprinter's Speed in C++


April 22, 2020 0.570674 seconds C++
#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;
	}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.