Skip to content

Conversation

@alirz-pixel
Copy link
Member

🚀 이슈 번호

Resolve: {#2314}

🧩 문제 해결

스스로 해결:

🔎 접근 과정

문제 해결을 위한 접근 방식을 설명해주세요.

  • 🔹 어떤 알고리즘을 사용했는지: 그리디
  • 🔹 어떤 방식으로 접근했는지

규칙에 의해 최종 승리자는 1번이 될 것이고,

가장 순위가 낮은 사람과 1번과는 배틀을 하는 케이스가 만들어져서는 안된다.

따라서 가장 순위가 낮은 사람을 기준으로 양 옆의 순위를 비교하여 차이가 낮은 대결이 진행하는 식으로하여
그리디를 진행할 수 있다.

⏱️ 시간 복잡도

시간 복잡도 분석을 작성해주세요.
최악의 경우 수행 시간은 어느 정도인지 분석합니다.

  • Big-O 표기법: O(N)
  • 이유:

대회가 많이 진행되더라도 입력값인 N을 넘을 수 없기 때문이다.

💻 구현 코드

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> rank;
	for (int i = 0; i < N; i++) {
		int input;
		cin >> input;

		rank.push_back(input);
	}

	int answer = 0;
	while (rank.size() != 1) {
		int max_v = 0;
		int max_i = -1;
		for (int i = 0; i < rank.size(); i++) {
			if (max_v < rank[i]) {
				max_i = i;
				max_v = rank[i];
			}
		}

		int cur_diff = 100000;
		if (0 < max_i)
			cur_diff = rank[max_i] - rank[max_i - 1];
		if (max_i < rank.size() - 1)
			cur_diff = min(cur_diff, rank[max_i] - rank[max_i + 1]);

		rank.erase(rank.begin() + max_i);
		answer += cur_diff;
	}

	cout << answer;


	return 0;
}

@alirz-pixel alirz-pixel self-assigned this Jan 19, 2026
@alirz-pixel alirz-pixel linked an issue Jan 19, 2026 that may be closed by this pull request
@alirz-pixel alirz-pixel merged commit e0f0ed4 into main Jan 25, 2026
1 check passed
@alirz-pixel alirz-pixel deleted the munhyeong/2314/2 branch January 25, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

260119 : 코딩테스트

2 participants