Source Code
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector <int> arr;
	int val, siz;
	cin >> siz;
	for (int x = 0; x < siz; x++)
	{
		cin >> val;
		arr.push_back(val);
	}
	int ind = 0;
	for (int x = 0; x < siz-1; x++)
	{
		if (arr.at(x) > arr.at(x + 1))
		{
			arr.at(x) += arr.at(x + 1);
			ind = x + 1;
			arr.erase(arr.begin() + ind);
			siz -= 1;
			x--;
		}
		else if (arr.at(x) == arr.at(x + 1))
		{
			if (arr.at(x+1) == arr.at(x + 2))
			{ 
				arr.at(x) += arr.at(x + 1);
				ind = x + 1;
				arr.erase(arr.begin() + ind);
				siz -= 1;
				x--;
			}
		}
	}
	for (int x = 0; x < siz; x++)
	{
		cout << arr.at(x) << " ";
	}


}
Copy
b master2000
GNU G++17
0 ms
548 KB
Wrong Answer