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)?