-
456-A, *1100코드포스 2021. 7. 23. 14:21
Problem - 456A - Codeforces
codeforces.com
문제
- 비싼데 더 구린 노트북이 있나?
- $O(nlog\ n)$ 정도 알고리즘은 통과가능하다
$O(nlog\ n)$
가격을 기준으로 sort 하고 $O(nlog\ n)$
낮은 가격부터 2개씩 비교하면서 비싼데 더 구린 노트북이 있는지 본다 $O(n)$1234567891011121314151617181920212223242526272829303132#include <bits/stdc++.h>#define endl "\n"using namespace std;vector<pair<int, int> > v;int main(){ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int n;cin >> n;int a, b;while(n--){cin >> a >> b;v.emplace_back(a, b);}sort(v.begin(), v.end());bool isAlexwrong = true;for(int i = 0; i < v.size()-1; i++){if(v[i].second > v[i+1].second){isAlexwrong = false;break;}}cout << (isAlexwrong? "Poor Alex": "Happy Alex") << endl;return 0;}cs'코드포스' 카테고리의 다른 글
368-B, *1100 (0) 2021.07.23 313-B, *1100 (0) 2021.07.23 519-B, *1100 (0) 2021.07.23 363-B, *1100 (0) 2021.07.22 270-A, *1100 (0) 2021.07.22