Szczegółowe omówienie zadania Lemonade Line z grupy srebrnej Amerykańskiej Olimpiady Informatycznej USACO:
Link do zadania:
http://www.usaco.org/index. php?page=viewproblem2&cpid=835
http://www.usaco.org/index.
Zadanie wymaga pomysłu i umiejętności sortowania!
#include <bits/stdc++.h> using namespace std; const int MAX_COWS = 1e5+10; int acceptance_level[MAX_COWS]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("lemonade.in", "r", stdin); freopen("lemonade.out", "w", stdout); int number_of_cows; int cows_in_line; int i; cin >> number_of_cows; for (i=1; i<=number_of_cows; ++i) { cin >> acceptance_level[i]; } sort (acceptance_level+1, acceptance_level+number_of_cows+1); cows_in_line = 0; for (i=number_of_cows; i>=1; --i) { if (acceptance_level[i] < cows_in_line) break; ++cows_in_line; } cout << cows_in_line; return 0; }