CSES - Concert Tickets

Author: Danh Ta Chi Thanh

Solution

Unofficial Editorial

Another way of solving the problem is to use the multiset::upper_bound function to find the lowest-priced ticket that exceeds the maximum price for the current customer. When we have found the iterator pointing to the upper bound, we just decrement the iterator to get the maximum price possible for that current customer. Note that if the initial iterator points to the beginning of the multiset, we can infer that there is no ticket that works for the customer.

(Proof for my solution)

#include <bits/stdc++.h>
using namespace std;
//variables used for the current problem
int n,m,h,t; multiset<int> tickets;
void solve() {
cin >> n >> m;
for (int i=0;i<n;++i){

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!