USACO December 2022 Bronze problem 1

Cow College

For this problem I found finding the total amount of money FJ makes very easy, but couldn’t find away using my current algorithm below to find the optimal tuition amount.

#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    
    //reading input
    vector<long long> tuitions;
    for (int i = 0; i < N; i++) {
        long long temp;
        cin >> temp;
        tuitions.push_back(temp);
    }

    sort(tuitions.begin(), tuitions.end());

    int highest_tuition;

    int tuition = 0;
    //main algorithm
    for (int i = 0; i < N; i++) {
        int money = (N-i)*tuitions[i];
        highest_tuition = max(highest_tuition, money);
    }

}

How would I, still using my current algorithm, keep track of the best tuition (as it is required by the problem)?

replace the max() statement with something like this

if (temp1 > money || (temp1 == money && temp2 < tuition)) {
                money = temp1;
                tuition = temp2;
}