HyPraT_'s blog

By HyPraT_, history, 15 months ago, In English

link to the problem: https://cses.fi/problemset/task/1091/

my first blog post... please excuse me for my way of writing blog

My solution: I) approach: use multiset for the ticket price, and vector for customers bidding, I switched input to -ve sign in set, so I can make the implementation easier...

code:


~~~~~ #include <bits/stdc++.h> using namespace std; int main(){ long long int tic,cus,h; multiset<int> price; cin >>tic >>cus; for(int i=0;i<tic;i++){ cin >>h; h = -h; price.insert(h); } vector <int> customer; for(int i=0;i<cus;i++){ cin >>customer[i]; } for(int k=0;k<cus;k++){ auto it=price.begin(); for(;it!=price.end();it++){ h = 0; if(abs(*it) <= customer[k]){ h = *it; it--; cout <<-h <<endl; price.erase(price.find(h)); break; } } if(it == price.end() && h ==0) cout <<-1 <<endl; } }

~~~~~

problem: code shows no output, and returns -10221910 etc... i couldn't find the reason for undefined behaviour.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it