ACM준비/algospot

KBODRAFT

조규현15 2015. 8. 5. 14:17
반응형

https://www.algospot.com/judge/problem/read/KBODRAFT

 

algospot.com :: KBODRAFT

이상한 드래프트 문제 정보 문제 2150년, Kureyo Baseball Organization(이하 KBO)은 100번째 구단의 창단을 승인하였다. 그 전까지는 지난 시즌의 순위에 따라 지그재그식으로 한 선수씩 선발하는 식이었지

www.algospot.com

[ 입력 -> 삭제 -> 삽입 -> 결과 ]의 반복임.

using namespace std;

struct CARD{
	CARD(int _index, int _power)
	{
		index = _index;
		power = _power;
	}
	int index;
	int power;
};

list PLAYER[9];
int PLAYERPOINT[9];

int findIndex(int index)
{
	if (PLAYER[index].size() > 0)
	{
		int BIGPOWER = -9999;
		list< CARD >::iterator iterEnd = PLAYER[index].end();
		for (list< CARD >::iterator iterPos = PLAYER[index].begin();
			iterPos != iterEnd;
			++iterPos)
		{
			BIGPOWER = (BIGPOWER < iterPos->power) ? iterPos->power : BIGPOWER;
		}
		return BIGPOWER;
	}
	else
		return 0;
}
int Add(int index, int score)
{
	if (score <= PLAYERPOINT[index])
		return 0;
	else
		PLAYERPOINT[index] = score;

	int OUTPUT = 0;
	for (int i = 0; i < 9; i++)
		if (PLAYERPOINT[i] == 0)
			return 0;
		else
			OUTPUT += PLAYERPOINT[i];

	return OUTPUT;
}
void Delete(int index)
{
	for (int i = 0; i < 9; i++){
		if (PLAYER[i].size() > 0)
		{
			CARD _CARD = PLAYER[i].front();
			if (_CARD.index == index)
			{
				PLAYER[i].pop_front();

				if (_CARD.power == PLAYERPOINT[i])
					PLAYERPOINT[i] = findIndex(i);
			}
		}
	}
}
int main()
{
	int CASE;
	for (scanf("%d", &CASE); CASE > 0; CASE--)
	{
		int N, K, OUTPUT = 0;

		memset(PLAYERPOINT, 0, sizeof(PLAYERPOINT));
		for (int i = 0; i < 9; i++)
			PLAYER[i].clear();

		scanf("%d %d", &N, &K);

		for (int i = 0; i < N; i++)
		{
			int P, A;
			scanf("%d %d", &P, &A);
			CARD _CARD(i, A);
			
			if (i + 1 > K)
				Delete(i - K);
			
			PLAYER[P - 1].push_back(_CARD);
			int output = Add(P - 1, A);
			
			OUTPUT = (OUTPUT < output) ? output : OUTPUT;

		}
		printf("%d\n", OUTPUT);
	}

	return 0;
}
반응형

'ACM준비 > algospot' 카테고리의 다른 글

PICNIC  (0) 2015.08.05
ZEROONE  (0) 2015.08.05
EDIAN  (0) 2015.08.04
GRIDISLANDS - 2  (0) 2015.07.30
GRIDISLANDS  (0) 2015.07.30