Problem:
Problem B. Colorful Drink
In the Jambo Amusement Garden (JAG), you sell colorful drinks consisting of multiple color layers. This colorful drink can be made by pouring multiple colored liquids of different density from the bottom in order.
You have already prepared several colored liquids with various colors and densities. You will receive a drink request with specified color layers. The colorful drink that you will serve must satisfy the following conditions.
You cannot use a mixed colored liquid as a layer. Thus, for instance, you cannot create a new liquid with a new color by mixing two or more different colored liquids, nor create a liquid with a density between two or more liquids with the same color by mixing them.
Only a colored liquid with strictly less density can be an upper layer of a denser colored liquid in a drink. That is, you can put a layer of a colored liquid with density $x$ directly above the layer of a colored liquid with density $y$ if $x < y$ holds.
Your task is to create a program to determine whether a given request can be fulfilled with the prepared colored liquids under the above conditions or not.
Input
The input consists of a single test case in the format below.
$N$
$C_1$ $D_1$
$\vdots$
$C_N$ $D_N$
$M$
$O_1$
$\vdots$
$O_M$
The first line consists of an integer $N$ ($1 \leq N \leq 10^5$), which represents the number of the prepared colored liquids. The following $N$ lines consists of $C_i$ and $D_i$ ($1 \leq i \leq N$). $C_i$ is a string consisting of lowercase alphabets and denotes the color of the $i$-th prepared colored liquid. The length of $C_i$ is between $1$ and $20$ inclusive. $D_i$ is an integer and represents the density of the $i$-th prepared colored liquid. The value of $D_i$ is between $1$ and $10^5$ inclusive. The ($N+2$)-nd line consists of an integer $M$ ($1 \leq M \leq 10^5$), which represents the number of color layers of a drink request. The following $M$ lines consists of $O_i$ ($1 \leq i \leq M$). $O_i$ is a string consisting of lowercase alphabets and denotes the color of the $i$-th layer from the top of the drink request. The length of $O_i$ is between $1$ and $20$ inclusive.
Output
If the requested colorful drink can be served by using some of the prepared colored liquids, print '
Yes
'. Otherwise, print '
No
'.
Examples
Sample Input 1
2
white 20
black 10
2
black
white
Output for Sample Input 1
Yes
Sample Input 2
2
white 10
black 10
2
black
white
Output for Sample Input 2
No
Sample Input 3
2
white 20
black 10
2
black
orange
Output for Sample Input 3
No
Sample Input 4
3
white 10
red 20
white 30
3
white
red
white
Output for Sample Input 4
Yes
Sample Input 5
4
red 3444
red 3018
red 3098
red 3319
4
red
red
red
red
Output for Sample Input 5
Yes

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

const ll INF = 1e18;
ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if (argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    ll n;
    cin >> n;
    map<string, vector<ll>> mp;
    for (int i = 0; i < n; i++) {
        string c;
        ll d;
        cin >> c >> d;
        mp[c].push_back(d);
    }
    for (auto& x : mp)
        sort(x.second.begin(), x.second.end());
    ll m;
    cin >> m;
    vector<string> query(m);
    for (auto& x : query) cin >> x;
    reverse(query.begin(), query.end());
    ll now = INF;
    for (auto& x : query) {
        if (mp[x].empty()) {
            cout << "No" << endl;
            return 0;
        }
        while (mp[x].size()) {
            ll num = mp[x].back();
            mp[x].pop_back();
            if (now > num) {
                now = num;
                break;
            }
            if (mp[x].empty()) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 26792
final_rank: 8

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;cin >> n;
  map<string,vector<int>> mp;
  rep(i,0,n){
    string c;int d;cin >> c >> d;
    mp[c].emplace_back(d);
  }
  for(auto &[s,v] : mp){
    sort(ALL(v));
  }
  int m;cin >> m;
  int cl = 0;
  rep(i,0,m){
    string O;cin >> O;
    auto &v = mp[O];
    int k = LB(v,cl+1);
    if(k >= sz(v)){
      cout << "No\n";
      return 0;
    }
    cl = v[k];
  }
  cout << "Yes\n";
  

  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 18984
final_rank: 5

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

int main() {
    ll n; cin >> n;
    vector<pair<ll, string>> liquid(n);
    rep(i, n) cin >> liquid[i].second >> liquid[i].first;

    sort(liquid.begin(), liquid.end());

    ll m; cin >> m;
    ll last_density = 0;
    ll use = 0;
    rep(_, m) {
        string request; cin >> request;

        while (use < liquid.size() && (last_density >= liquid[use].first || request != liquid[use].second)) {
            use++;
        }
        if (use == liquid.size()) {
            cout << "No" << "\n";
            return 0;
        }

        last_density = liquid[use].first;
    }

    cout << "Yes" << "\n";
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 11724
final_rank: 1

code_snippet: ////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
map<string,int> ms;
vector<int> vec[N + 5];
string s[N + 5];

void hora(int tc) {
	int n;
	cin>>n;
	int id = 0;
	for(int i = 0;i < n;i++) {
		string s;
		int x;
		cin>>s>>x;
		if(ms[s] == 0) ms[s] = ++id;
		int w = ms[s];
		vec[w].PB(x);
	}
	for(int i = 1;i <= id;i++) sort(vec[i].begin(), vec[i].end());
	int q;
	cin>>q;
	for(int i = 0;i < q;i++) cin>>s[i];
	int last = 1e6;
	bool bisa = true;
	for(int i = q - 1;i >= 0;i--) {
		int w = ms[s[i]];
		while(!vec[w].empty() && vec[w].back() >= last) vec[w].POB();
		if(vec[w].empty()) {
			bisa = false;
			break;
		}
		last = vec[w].back();
	}
	cout<<((bisa == true)?"Yes":"No")<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 27684
final_rank: 11

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int N;
    std::cin >> N;
    std::map<std::string, std::vector<int>> map;
    for (int i{} ; i < N ; i++) {
        std::string S;
        int A;
        std::cin >> S >> A;
        map[S].push_back(A);
    }
    for (auto& [_, arr] : map) std::sort(arr.begin(), arr.end());
    int cur{};
    int M;
    std::cin >> M;
    bool can{true};
    for (int i{} ; can and i < M ; i++) {
        std::string S;
        std::cin >> S;
        auto it{map.find(S)};
        if (it == map.end()) can = false;
        else {
            auto it2{std::upper_bound(it->second.begin(), it->second.end(), cur)};
            if (it2 == it->second.end()) can = false;
            else cur = *it2;
        }
    }
    std::cout << (can ? "Yes\n" : "No\n");
}
accuracy: 1
time_ms: 90
memory_kb: 19084
final_rank: 4

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 25;
static char buf[MAX_N];
//------------------------------------------------------------------------------
typedef priority_queue<int, vector<int>, greater<int> > PQ;
typedef unordered_map<string,PQ> Drinks;
//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, K, v, num;
    num = scanf("%d ", &N);
    Drinks drinks;
    string color;
    for (int i=0; i<N; ++i)
    {
        num = scanf("%s %d ", buf, &v);
        color = string(buf);
        if (drinks.find(color) == drinks.end()) drinks[ color ] = PQ();
        drinks[ color ].push( v );
    }

    bool ok = true;
    int value = 0;
    num = scanf("%d ", &K);
    for (int k=0; k<K; ++k)
    {
        num = scanf("%s ", buf);
        if (!ok) continue;
        color = string(buf);

        if (drinks.find(color) == drinks.end() || drinks[color].empty())
        {
            if (DEBUG)
            {
                printf("k=%d: color=%s, ", k, color.c_str());
                if (drinks.find(color) == drinks.end()) printf("not found\n");
                else printf("used up\n");
            }
            ok = false;
            continue;
        }
 
        while (!drinks[color].empty() && drinks[color].top() <= value) drinks[color].pop();
        if (drinks[color].empty()) { ok = false; continue; }

        value = drinks[color].top();
        drinks[color].pop();
    }
    if (ok) printf("Yes\n");
    else printf("No\n");
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 70
memory_kb: 19452
final_rank: 3

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 25;
static char buf[MAX_N];
//------------------------------------------------------------------------------
typedef priority_queue<int, vector<int>, greater<int> > PQ;
typedef unordered_map<string,PQ> Drinks;
//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, K, v, num;
    num = scanf("%d ", &N);
    Drinks drinks;
    string color;
    for (int i=0; i<N; ++i)
    {
        num = scanf("%s %d ", buf, &v);
        color = string(buf);
        if (drinks.find(color) == drinks.end()) drinks[ color ] = PQ();
        drinks[ color ].push( v );
    }

    bool ok = true;
    int value = 0;
    num = scanf("%d ", &K);
    for (int k=0; k<K; ++k)
    {
        num = scanf("%s ", buf);
        if (!ok) continue;
        color = string(buf);

        if (drinks.find(color) == drinks.end() || drinks[color].empty()) { ok = false; continue; }
        if (drinks[color].top() <= value) { ok = false; continue; }
        value = drinks[color].top();
        drinks[color].pop();
    }
    if (ok) printf("Yes\n");
    else printf("No\n");
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 0.40816326530612246
time_ms: 40
memory_kb: 17320
final_rank: 17

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
    int N, M;
    vector<string> C, O;
    vector<int> D;
    cin >> N;
    C.resize(N), D.resize(N);
    rep(i,0,N) cin >> C[i] >> D[i];
    cin >> M;
    O.resize(M);
    rep(i,0,M) cin >> O[i];
    map<string,int> mp;
    rep(i,0,N) {
        mp[C[i]] = i;
    }
    rep(i,0,M) {
        if (mp.count(O[i]) == 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    vector<vector<int>> V(N);
    rep(i,0,N) {
        V[mp[C[i]]].push_back(D[i]);
    }
    rep(i,0,N) {
        sort(ALL(V[i]));
    }
    vector<int> ID(N,0);
    int Cur = -1;
    rep(i,0,M) {
        int Now = mp[O[i]];
        bool check = false;
        while(ID[Now] < V[Now].size()) {
            if (V[Now][ID[Now]] > Cur) {
                Cur = V[Now][ID[Now]];
                ID[Now]++;
                check = true;
                break;
            }
            ID[Now]++;
        }
        if (!check) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
accuracy: 1
time_ms: 210
memory_kb: 36072
final_rank: 15

code_snippet: // competitive-verifier: PROBLEM
#ifdef ATCODER
#pragma GCC target("sse4.2,avx512f,avx512dq,avx512ifma,avx512cd,avx512bw,avx512vl,bmi2")
#endif
#pragma GCC optimize("Ofast,fast-math,unroll-all-loops")
#include <bits/stdc++.h>
#ifndef ATCODER
#pragma GCC target("sse4.2,avx2,bmi2")
#endif
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = 3.14159265358979323846;
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(20);
    }
    constexpr void operator()() const {}
} sonic;
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) os << (it == v.begin() ? "" : " ") << *it;
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
void Yes(bool is_correct = true) { std::cout << (is_correct ? "Yes\n" : "No\n"); }
void No(bool is_not_correct = true) { Yes(!is_not_correct); }
void YES(bool is_correct = true) { std::cout << (is_correct ? "YES\n" : "NO\n"); }
void NO(bool is_not_correct = true) { YES(!is_not_correct); }
void Takahashi(bool is_correct = true) { std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n'; }
void Aoki(bool is_not_correct = true) { Takahashi(!is_not_correct); }
int main(void)
{
    int n;
    cin >> n;
    vector<string> c(n);
    vector<int> d(n);
    rep(i, n) cin >> c[i] >> d[i];
    int m;
    cin >> m;
    vector<string> o(m);
    cin >> o;
    vector<int> ord(n);
    iota(all(ord), 0);
    sort(all(ord), [&](int x, int y)
         { return d[x] < d[y]; });
    int p = -1;
    int k = 0;
    rep(i, m)
    {
        string s = o[i];
        while (k < n && (c[ord[k]] != s || d[ord[k]] <= p))
            ++k;
        if (k == n)
        {
            No();
            return 0;
        }
        p = d[ord[k]];
    }
    Yes();
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 19512
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	map<string,int> m, ordered;
	cin>>n;
	vector<pair<int,string>> l(n);
	for(int i=0;i<n;i++){
		string s;
		int j;
		cin>>s>>j;
		m[s]++;
		l[i].first=j;
		l[i].second=s;

	}
	int q;
	cin>>q;
	vector<string> menu(q);
	for(int i=0;i<q;i++){
		string s;
		cin>>s;
		menu[i]=s;
		ordered[s]++;
	}
	bool able = true;
	for(int i=0;i<q;i++){
		string t;
		t=menu[i];
		if(m[t]<ordered[t]){
			able=false;
		}	
	}
	set<int> check;
	queue<pair<int,string>> que;
	sort(l.begin(),l.end());
	reverse(l.begin(),l.end());
	for(int i=0;i<n;i++){
		que.push(l[i]);
	}
	reverse(menu.begin(),menu.end());
	int count=0;
	while(!que.empty() and count<q){
		pair<int,string> p;
		p=que.front();
		que.pop();

		if(p.second!=menu[count]){
			continue;
		}else{
			count++;
			check.insert(p.first);
		}
	}
	if(count!=q or check.size()!=q){
		able=false;
	}
	

	if(able){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}
accuracy: 0.40816326530612246
time_ms: 200
memory_kb: 32060
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1e18 + 10
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b; 
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  //while(1){
    int n;
    map<string,vector<int>> mp;
    cin>>n;
    
    rep(i,n){
      string s;
      int num;
      cin>>s>>num;
      mp[s].push_back(num);
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      sort(itr->S.begin(),itr->S.end());
    }
    cin>>n;
    int prev=-1;
    bool flag=false;
    rep(i,n){
      string s;
      cin>>s;
      if(mp.find(s)==mp.end() ) flag=true;
      else if(mp[s].size() == 0) flag=true;
      if(flag) continue;
      //cout<<prev<<" "<<mp[s][0]<<endl;
      while(mp[s].size() != 0 && mp[s][0]<=prev)
	  mp[s].erase(mp[s].begin(),mp[s].begin()+1);
      if(mp[s].size() == 0) flag=true;
	
      else{
	prev=mp[s][0];
	mp[s].erase(mp[s].begin(),mp[s].begin()+1);
	
      }
    }
    if(!flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	
      
    

  return 0;
}
accuracy: 1
time_ms: 540
memory_kb: 19092
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1e18 + 10
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b; 
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  //while(1){
    int n;
    map<string,vector<int>> mp;
    cin>>n;
    
    rep(i,n){
      string s;
      int num;
      cin>>s>>num;
      mp[s].push_back(num);
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      sort(itr->S.begin(),itr->S.end());
    }
    cin>>n;
    int prev=-1;
    bool flag=false;
    rep(i,n){
      string s;
      cin>>s;
      if(mp.find(s)==mp.end() ) flag=true;
      if(mp[s].size() == 0) flag=true;
      if(flag) continue;
      //cout<<prev<<" "<<mp[s][0]<<endl;
      if(!chmax(prev,mp[s][0])){
	
	flag=true;
      }else{
	int num=mp[s][0];
	while(mp[s].size() != 0 && mp[s][0]==num)
	  mp[s].erase(mp[s].begin(),mp[s].begin()+1);
	
      }
    }
    if(!flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	
      
    

  return 0;
}
accuracy: 0.40816326530612246
time_ms: 100
memory_kb: 16768
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1e18 + 10
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b; 
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  //while(1){
    int n;
    map<string,vector<int>> mp;
    cin>>n;
    
    rep(i,n){
      string s;
      int num;
      cin>>s>>num;
      mp[s].push_back(num);
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      sort(itr->S.begin(),itr->S.end());
    }
    cin>>n;
    int prev=-1;
    bool flag=false;
    rep(i,n){
      string s;
      cin>>s;
      if(mp.find(s)==mp.end() ) flag=true;
      if(mp[s].size() == 0) flag=true;
      if(flag) continue;
      //cout<<prev<<" "<<mp[s][0]<<endl;
      if(!chmax(prev,mp[s][0])){
	
	flag=true;
      }else{
	
	mp[s].erase(mp[s].begin(),mp[s].begin()+1);
      }
    }
    if(!flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	
      
    

  return 0;
}
accuracy: 0.40816326530612246
time_ms: 100
memory_kb: 16832
final_rank: 19

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i =0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 998244353;
const int inf ( 1<<30);


int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);

	int n;
	cin>>n;

	map<string, priority_queue<int>> color_to_pq;

	for(int i=0;i<n;i++) {
		string c;
		int d;
		cin>>c>>d;

		color_to_pq[c].push(d);
	}

	int m;
	cin>>m;

	vector<string> o(m);

	for(int i=0;i<m;i++) {
		cin>>o[i];
	}

	int last_d = inf;

	for(int i=o.size() - 1; i >= 0; i--) {
		if (color_to_pq[o[i]].empty()) {
			cout << "No" << endl;
			return 0;
		}

		int d = color_to_pq[o[i]].top();
		color_to_pq[o[i]].pop();

		while(last_d <= d) {
			if (color_to_pq[o[i]].empty()) {
				cout << "No" << endl;
				return 0;
			}

			d = color_to_pq[o[i]].top();
			color_to_pq[o[i]].pop();
		}

		last_d = d;
	}

	cout << "Yes" << endl;
}
accuracy: 1
time_ms: 130
memory_kb: 28168
final_rank: 12

code_snippet: #include<bits/stdc++.h>

using namespace std;

bool func(){
  int n;
  cin >> n;
  map<string,set<int>> colors;
  for(int i=0;i<n;++i){
    string color;
    int density;
    cin >> color >> density;
    colors[color].insert(density);
  }
  int last = -1e9;
  int m;
  cin >> m;
  for(int i=0;i<m;++i){
    string need;
    cin >> need;
    if(colors.count(need)==0)return false;
    auto itr = colors[need].upper_bound(last);
    if(itr == colors[need].end())return false;
    last = *itr;
  }
  return true;
}

int main(){
  cout << (func() ? "Yes" : "No") << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 23692
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
	int N; cin >> N;
	map<string, vector<int>> mp{};
	for (int i = 0 ; i < N ; i++) {
		string c; cin >> c;
		int d; cin >> d;
		mp[c].push_back(d);	
	}
	for (auto& [_, arr] : mp) sort(arr.begin(), arr.end(), greater<int>());

	int M; cin >> M;
	int now = 0;
	bool ok = true;
	for (int _ = 0 ; _ < M and ok ; _++) {
		string O; cin >> O;
		bool tmp = false;
		while (!mp[O].empty()) {
			if (mp[O].back() > now) {
				now = mp[O].back();
				tmp = true;
				mp[O].pop_back();
				break;
			}
			mp[O].pop_back();
		}
		ok &= tmp;
	}

	cout << (ok ? "Yes" : "No") << endl;
}
accuracy: 1
time_ms: 190
memory_kb: 18976
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define per(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define per2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define each(e, v) for (auto &e : v)
#define MM << " " <<
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
using maxheap = priority_queue<T>;

template <typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}

template <typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}

template <typename T>
int flg(T x, int i) {
    return (x >> i) & 1;
}

template <typename T>
void print(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (v.empty()) cout << '\n';
}

template <typename T>
void printn(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++) cout << v[i] + x << '\n';
}

template <typename T>
int lb(const vector<T> &v, T x) {
    return lower_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
int ub(const vector<T> &v, T x) {
    return upper_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
void rearrange(vector<T> &v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <typename T>
vector<int> id_sort(const vector<T> &v, bool greater = false) {
    int n = v.size();
    vector<int> ret(n);
    iota(begin(ret), end(ret), 0);
    sort(begin(ret), end(ret), [&](int i, int j) { return greater ? v[i] > v[j] : v[i] < v[j]; });
    return ret;
}

template <typename S, typename T>
pair<S, T> operator+(const pair<S, T> &p, const pair<S, T> &q) {
    return make_pair(p.first + q.first, p.second + q.second);
}

template <typename S, typename T>
pair<S, T> operator-(const pair<S, T> &p, const pair<S, T> &q) {
    return make_pair(p.first - q.first, p.second - q.second);
}

template <typename S, typename T>
istream &operator>>(istream &is, pair<S, T> &p) {
    S a;
    T b;
    is >> a >> b;
    p = make_pair(a, b);
    return is;
}

template <typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
    return os << p.first << ' ' << p.second;
}

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
// const int MOD = 1000000007;
const int MOD = 998244353;

int main() {
    int N;
    cin >> N;

    map<string, vector<int>> mp;

    rep(i, N) {
        string S;
        int x;
        cin >> S >> x;
        mp[S].eb(x);
    }

    each(e, mp) sort(rall(e.second));

    int Q;
    cin >> Q;

    int last = 0;

    while (Q--) {
        string T;
        cin >> T;

        auto v = mp[T];
        while (!empty(v) && v.back() <= last) v.pop_back();

        if (empty(v)) {
            cout << "No\n";
            return 0;
        }

        last = v.back();
        mp[T] = v;
    }

    cout << "Yes\n";
}
accuracy: 1
time_ms: 460
memory_kb: 19088
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define inf 1e9
#define INF 1e17
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    vector<vector<int>> v(n);
    int cnt = 0;
    rep(i, n){
        string c;
        int d;
        cin >> c >> d;
        if(mp.find(c) == mp.end()){
            v[cnt].emplace_back(d);
            mp[c] = cnt++;
        }
        else v[mp[c]].emplace_back(d);
    }
    rep(i, cnt)sort(all(v[i]));
    int m, now = 0;
    cin >> m;
    rep(i, m){
        string s;
        cin >> s;
        if(mp.find(s) == mp.end()){
            cout << "No" << endl;
            return 0;
        }
        auto ite = upper_bound(all(v[mp[s]]), now);
        if(ite == v[mp[s]].end()){
            cout << "No" << endl;
            return 0;
        }
        now = *ite;
    }
    cout << "Yes" << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 19360
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define inf 1e9
#define INF 1e17
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    vector<vector<int>> v(n);
    int cnt = 0;
    rep(i, n){
        string c;
        int d;
        cin >> c >> d;
        if(mp.find(c) == mp.end()){
            v[cnt].emplace_back(d);
            mp[c] = cnt++;
        }
        else v[mp[c]].emplace_back(d);
    }
    rep(i, cnt)sort(all(v[i]));
    int m, now = 0;
    cin >> m;
    rep(i, m){
        string s;
        cin >> s;
        if(mp.find(s) == mp.end()){
            cout << "No" << endl;
            return 0;
        }
        auto ite = lower_bound(all(v[mp[s]]), now);
        if(*ite == now)ite++;
        if(ite == v[mp[s]].end()){
            cout << "No" << endl;
            return 0;
        }
        now = *ite;
    }
    cout << "Yes" << endl;
}
accuracy: 0.8571428571428571
time_ms: 200
memory_kb: 19448
final_rank: 16

code_snippet: // author: hanyu
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  map<string, vector<int>> mp;
  for (int i = 0; i < n; i++) {
    string c;
    int d;
    cin >> c >> d;
    mp[c].emplace_back(d);
  }

  for (auto &i : mp) {
    sort(i.second.begin(), i.second.end());
  }

  int m;
  cin >> m;

  vector<string> o(m);
  for (int i = 0; i < m; i++) cin >> o[i];

  bool ok = true;
  int now = -1;
  for (int i = 0; i < m; i++) {
    if (mp.find(o[i]) == mp.end()) {
      ok = false;
      break;
    }
    auto it = upper_bound(mp[o[i]].begin(), mp[o[i]].end(), now);
    if (it == mp[o[i]].end()) {
      ok = false;
      break;
    }
    now = *it;
  }

  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 26584
final_rank: 9