LoginSignup
0
0

More than 3 years have passed since last update.

ABC 112-B priority_queueの使いかた

Last updated at Posted at 2019-09-28

priority_queueとは?

C++で利用できるコンテナ・アダプタの1つで、優先順位付きキューを実現しているもの。

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;

priority_queue<int, vector<int>, greater<int>> A;//箱Aのtopが小,bottomが大の並び方にした

int main(){
    int N,T; cin >> N >> T;
    int c,t;
    rep(i,N){
        cin >> c >> t;
        if (t<=T) A.push(c);
    }
    if (A.empty()) cout << "TLE" << endl;//箱Aの中身が空ならTLE
    else cout << A.top() << endl;//箱Aの中身がある場合、topの一番小さい値をとりだす!
}

まとめ

箱Aの中身を自分で操作しなくても、昇順降順に自動で分けられるので簡単!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0