[ Codeforces ] 489B: Laptops | C++

Поделиться
HTML-код
  • Опубликовано: 18 янв 2025

Комментарии • 2

  • @LeekCodeDev
    @LeekCodeDev  12 дней назад

    I was trying to figure out how I would compare each pair with every other pair before it, and this seemed quite tedious, so I realize that if I just sort by one trait, such as price, and I know that price is increasing, the quality must also be increasing, and if one case is where the quality actually decreased, then we know that Alex was right and he'd be happy. Otherwise, Alex would be wrong. Looks easy at first but took a bit of thinking :)

  • @LeekCodeDev
    @LeekCodeDev  12 дней назад +1

    Source Code:
    #include
    using namespace std;
    #define fastread() { ios::sync_with_stdio(0);cin.tie(0);}
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    int main(){
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fastread();
    int n;
    cin >> n;
    vector pairsArr;
    while(n--) {
    int a,b;
    cin >> a >> b;
    pairsArr.push_back(make_pair(a,b));
    }
    sort(begin(pairsArr),end(pairsArr), [](auto& l, auto& r) {
    return l.first < r.first;
    });
    bool happyAlex = false;
    for(int i=1;i