겹치는 docs cost를 고려해서 queue를 사용하는 문제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <iostream> #include <list> #include <algorithm> using namespace std; int main() { int cases; cin >> cases; while (cases--) { int N, T; cin >> N >> T; list<pair<int, bool>> docs; list<int> maxDocs; for (int i = 0; i < N; i++) { int val; cin >> val; if (i == T) { docs.push_back(make_pair(val, true)); } else { docs.push_back(make_pair(val, false)); } maxDocs.push_back(val); } maxDocs.sort(); int cnt = 0; while (!docs.empty()) { if (docs.front().first < maxDocs.back()) { docs.push_back(docs.front()); docs.pop_front(); } else { cnt++; if (docs.front().second) { cout << cnt << "\n"; break; } maxDocs.pop_back(); docs.pop_front(); } } } //system("pause"); return 0; } | cs |
'* Computer Science > Algorithm' 카테고리의 다른 글
baekjun 7576. 토마토 (0) | 2018.10.05 |
---|---|
baekjun 조세푸스 수열 (0) | 2018.08.27 |
baekjun 9012. 괄호 (0) | 2018.08.22 |
baekjun 1874. 스택 순열 (0) | 2018.08.22 |
baekjun 9252. LCS2 (0) | 2018.08.20 |