Click Here to go back to the homepage.

Driver's Dilemma Solution:


#include <bits/stdc++.h>
using namespace std;

int main() {
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    double C, X, M;
    cin >> C >> X >> M;
    array<double, 6> MPG = {};
    for(double &i :MPG) {
        cin >> i >> i;
    }
    C /= 2;
    bool yes = false;
    int mph = 80;
    for (int i = MPG.size() - 1; i >= 0; i--)
    {
        double hours = M / mph;
        if(hours * X + M / MPG[i] <= C){
            cout << "YES " << mph << endl;
            yes = true;
            break;
        }
        mph -= 5;
    }
    if(!yes){
        cout << "NO" << endl;
    }


    return 0;
}