본문 바로가기
  • Let's study
PS/백준

[C++] 백준 16206번: 롤케이크

by 코딩고수이고파 2021. 1. 23.

1. 10의 배수를 먼저 크기 순서대로 정렬한 후 나머지 숫자는 뒤에 붙인다.

2. 배열을 돌면서 10보다 크고 m>0일 동안 v[i]에서 10을 빼면서 카운트를 센다.

3. v[i]가 10인 경우를 따로 카운트 해준다.

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

using namespace std;

vector<int>v;
vector<int>v2;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m, a;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 10 == 0)
			v.push_back(a);
		else
			v2.push_back(a);
	}
	sort(v.begin(), v.end());

	for (int i = 0; i < v2.size(); i++) {
		v.push_back(v2[i]);
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		while (m>0 && v[i] > 10) {
			v[i] -= 10;
			cnt++;
			m--;
		}
		if (v[i] == 10) {
			cnt++;
		}
	}
	cout << cnt;
}

'PS > 백준' 카테고리의 다른 글

[C++] 백준 6764번: Sounds fishy!  (0) 2021.03.13
[C++] 백준 10799번: 쇠막대기  (0) 2021.02.04
[C++] 백준 2110번: 공유기 설치  (0) 2020.12.30
[C++] 백준 10870번: 피보나치 수 5  (0) 2020.12.27
[C++] 백준 2292번: 벌집  (0) 2020.12.26

댓글