Submission #495643

# Submission time Handle Problem Language Result Execution time Memory
495643 2021-12-19T17:07:27 Z Amer Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
17 / 100
3000 ms 83248 KB
#include <iostream>
#include<map>
#include<vector>

using namespace std;

class mem
{
public:
	int maxCombination = 0;
	int maxNumber = 0;
	int lastIndex = 0;
};


const int maxN = 1000005;

int arr[maxN];

map<int, vector<mem>> memorisation;

int solve(int start, int finish, int mood)
{
	bool possible = true;

	mem now;

	now.lastIndex = finish;
	now.maxNumber = arr[start - 1];
	now.maxCombination = 0;

	for (int i = start; i < finish; i++)
	{
		if (memorisation[i].size() != 0)
		{
			for (int j = 0; j < memorisation[i].size(); j++)
			{
				if (memorisation[i][j].lastIndex < finish)
				{
					if (memorisation[i][j].maxCombination > mood)
					{
						return false;
					}
				}
			}
		}

		if (now.maxNumber > arr[i])
		{
			if (arr[i] + now.maxNumber > mood)
			{
				possible = false;
			}

			if (arr[i] + now.maxNumber > now.maxCombination)
			{
				now.maxCombination = arr[i] + now.maxNumber;
			}
		}
		else
		{
			now.maxNumber = arr[i];
		}
	}

	memorisation[start].push_back(now);

	return possible;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    int n, m;

    cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	for (int i = 0; i < m; i++)
	{
		int start, finish, mood;

		cin >> start >> finish >> mood;

		cout << solve(start, finish, mood)<<endl;
	}
}

/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/

Compilation message

sortbooks.cpp: In function 'int solve(int, int, int)':
sortbooks.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<mem>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    for (int j = 0; j < memorisation[i].size(); j++)
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
11 Correct 8 ms 460 KB Output is correct
12 Correct 15 ms 816 KB Output is correct
13 Correct 16 ms 716 KB Output is correct
14 Correct 21 ms 892 KB Output is correct
15 Correct 20 ms 896 KB Output is correct
16 Correct 570 ms 968 KB Output is correct
17 Correct 277 ms 800 KB Output is correct
18 Correct 158 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 83248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3019 ms 9476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
11 Correct 8 ms 460 KB Output is correct
12 Correct 15 ms 816 KB Output is correct
13 Correct 16 ms 716 KB Output is correct
14 Correct 21 ms 892 KB Output is correct
15 Correct 20 ms 896 KB Output is correct
16 Correct 570 ms 968 KB Output is correct
17 Correct 277 ms 800 KB Output is correct
18 Correct 158 ms 812 KB Output is correct
19 Execution timed out 3031 ms 19152 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
11 Correct 8 ms 460 KB Output is correct
12 Correct 15 ms 816 KB Output is correct
13 Correct 16 ms 716 KB Output is correct
14 Correct 21 ms 892 KB Output is correct
15 Correct 20 ms 896 KB Output is correct
16 Correct 570 ms 968 KB Output is correct
17 Correct 277 ms 800 KB Output is correct
18 Correct 158 ms 812 KB Output is correct
19 Execution timed out 3041 ms 83248 KB Time limit exceeded
20 Halted 0 ms 0 KB -