USACO 2018 US Open Contest Silver Division - Lemonade Line#
Problem link: here
Solution Author: Stefan Dascalescu
Problem Solution#
Sort the list in descending order and if the index becomes larger than the number, stop and print the index it reached.
Source code#
The source code in C++ can be seen below.
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int main() {
ifstream cin("lemonade.in");
ofstream cout("lemonade.out");
int n;
cin >> n;
vector<int> cows;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
cows.push_back(temp);
}
sort(cows.begin(), cows.end());
int counter = 0;
for (int i = n - 1; i >= 0; i--) {
if (counter <= cows[i]) {
counter++;
}
else {
break;
}
}
cout << counter << '\n';
return 0;
}