답안 #341309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341309 2020-12-29T12:54:47 Z _ani Gift (IZhO18_nicegift) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
const int N = 1'000'002;
pair<ll,int> a[N];
priority_queue<pair<ll, int>> q;
vector<pair<ll, vector<int>>>ans;
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		q.push({ x, i });
	}
	while (!q.empty()) {
		vector<int> cur;
		if (q.size() < k)
		{
			cout << -1;
			return 0;
		}
		for (int i = 0; i < k; i++)
		{
			a[i] = q.top();
			cur.push_back(a[i].second);
			q.pop();
		}
		for (int i = 0; i < k - 1; i++)
		{
			a[i].first -= a[k - 1].first;
			if (a[i].first)q.push(a[i]);
		}
		ans.push_back({ a[k - 1].first,cur });
	}
	cout << ans.size() << '\n';
	for (auto b: ans)
	{
		cout << b.first << ' ';
		sort(b.second.begin(), b.second.end());
		for (auto x : b.second)
			cout << x + 1 << ' ';
		cout << '\n';
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:22:16: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |   if (q.size() < k)
      |       ~~~~~~~~~^~~
nicegift.cpp:44:3: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   44 |   sort(b.second.begin(), b.second.end());
      |   ^~~~
      |   qsort