91892024-02-17 19:36:34CWMZárójelekcpp17Wrong answer 14/10029ms12456 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<int, pair<int,int>>> sortedVec(n);
	for (int i = 0; i < n; i++)
	{
		int minC = 0;
		int totalProfit = 0;
		string s;
		cin >> s;
		for (size_t j = 0; j < s.size(); j++)
		{
			if (s[j] == '(') {
				totalProfit++;
			}
			else {
				totalProfit--;
				minC = min(minC, totalProfit);
			}
		}
		sortedVec[i] = { minC, {totalProfit, i } };
	}
	std::sort(sortedVec.begin(), sortedVec.end());
	std::reverse(sortedVec.begin(), sortedVec.end());
	int profit = 0;
	vector<int> res;
	for (size_t i = 0; i < n; i++)
	{
		if (profit >= sortedVec[i].first) {
			profit += sortedVec[i].second.first;
			res.push_back(sortedVec[i].second.second);
		}
		else {
			cout << "-1";
			break;
		}
	}
	for (size_t i = 0; i < res.size(); i++)
	{
		cout << res[i]+1 << " ";
	}
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1940 KiB
2Accepted8ms2484 KiB
subtask20/11
3Accepted3ms2660 KiB
4Wrong answer3ms2660 KiB
5Wrong answer3ms2844 KiB
6Accepted3ms3060 KiB
7Accepted8ms3912 KiB
8Wrong answer8ms4216 KiB
subtask30/6
9Accepted8ms4032 KiB
10Wrong answer8ms4360 KiB
11Wrong answer8ms4452 KiB
subtask414/14
12Accepted8ms4904 KiB
13Accepted8ms5300 KiB
subtask50/23
14Wrong answer8ms5624 KiB
15Wrong answer8ms5800 KiB
subtask60/19
16Wrong answer8ms6004 KiB
17Wrong answer8ms6212 KiB
18Accepted8ms6696 KiB
19Wrong answer8ms7064 KiB
20Wrong answer8ms7176 KiB
21Wrong answer6ms7628 KiB
22Wrong answer6ms7920 KiB
23Wrong answer6ms8008 KiB
24Wrong answer6ms7976 KiB
subtask70/27
25Wrong answer8ms8052 KiB
26Wrong answer8ms8340 KiB
27Wrong answer9ms8696 KiB
28Wrong answer9ms9016 KiB
29Wrong answer13ms9572 KiB
30Wrong answer29ms11180 KiB
31Wrong answer8ms9764 KiB
32Wrong answer8ms10000 KiB
33Wrong answer8ms10160 KiB
34Wrong answer9ms10424 KiB
35Wrong answer7ms10392 KiB
36Wrong answer9ms10844 KiB
37Wrong answer8ms11060 KiB
38Wrong answer8ms11232 KiB
39Wrong answer16ms12308 KiB
40Wrong answer4ms11940 KiB
41Wrong answer3ms11832 KiB
42Accepted7ms12216 KiB
43Wrong answer6ms12456 KiB