PS
BOJ 31797 : 아~파트 아파트
lickelon
2024. 12. 10. 23:15
- 문제 링크 : boj.kr/31797
- 난이도 : S4
- 태그 : 정렬
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<pii> arr(m*2);
for(int i = 0; i < m; i++) {
cin >> arr[i*2].first >> arr[i*2+1].first;
arr[i*2].second = arr[i*2+1].second = i+1;
}
sort(all(arr));
cout << arr[(n-1)%(m*2)].second;
return 0;
}
풀이
손의 높이로 정렬하고, 손의 수로 나누어 나머지를 구하고 해당 손의 주인을 출력한다.
728x90