Submission details
Task:Lisäykset
Sender:pupukani
Submission time:2025-11-29 10:53:47 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:32:47: error: cannot bind non-const lvalue reference of type 'std::_Rb_tree_iterator<std::pair<const int, int> >&' to an rvalue of type 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'}
   32 |                         auto& it = luvut.begin();
      |                                    ~~~~~~~~~~~^~

Code

#include <iostream>
#include <map>
#include <unordered_map>
#include <string>
#include <sstream>

int main(void)
{
	int n, m;
	std::cin >> n >> m;
	std::cin.ignore();

	std::string alkusis;
	std::getline(std::cin, alkusis);
	std::stringstream ss(alkusis);

	std::map<int, int> luvut;
	int luku;
	while (ss >> luku)
		luvut[luku]++;

	std::string ope;
	std::getline(std::cin, ope);
	std::stringstream sope(ope);

	int k;
	while (sope >> k)
	{
		std::unordered_map<int, int> lis;
		while (k > 0)
		{
			auto& it = luvut.begin();
			int luku = it->first;
			int maara = it->second;

			int sub = k >= maara ? maara : k;
			k -= sub;
			it->second -= sub;

			if (it->second == 0)
				luvut.erase(it);

			lis[luku + 1] += sub;
		}
		for (const auto& [luku, maara] : lis)
			luvut[luku] += maara;
	}

	std::string str;
	for (const auto& [luku, maara] : luvut)
	{
		for (int i = 0; i < maara; ++i)
			str += std::to_string(luku) + " ";
	}
	std::cout << str << std::endl;
}