Submission #495643

#TimeUsernameProblemLanguageResultExecution timeMemory
495643AmerHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
17 / 100
3041 ms83248 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...