Решения задачи выглядят одинаково, но одно не проходит по времени
Это проблема с сайта CSES "Concert Tickets"
https://cses.fi/problemset/task/1091/
Ниже мое решение
#include <bits/stdc++.h>
#define int long long
using namespace std;
multiset<int> h;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin>>n>>m;
for (int i = 0; i < n; ++ i)
{
int x;
cin>>x;
h.insert(x);
}
for (int i = 0; i < m; ++ i)
{
int x;
cin>>x;
auto it = upper_bound(x);
if (it != h.begin())
{
--it;
cout<<*it<<"\n";
h.erase(it);
}
else
{
cout<<"-1\n";
}
}
}
А вот решение с сайта, которое проходит все тесты в отличие от моего(TL на 4). Не понимаю, что конкретно я написал не так, из-за чего не проходит на всех тестах
#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){
cin >> h; tickets.insert(h);
}
for (int i=0;i<m;++i){
cin >> t;
auto it = tickets.upper_bound(t);
if (it==tickets.begin()){
cout << -1 << "\n";
}
else{
cout << *(--it) << "\n";
tickets.erase(it);
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
Источник: Stack Overflow на русском