Submission #900091

#TimeUsernameProblemLanguageResultExecution timeMemory
900091mannshah1211Detecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include "molecules.h" std::vector<int> find_subset(int l, int u, std::vector<int> w) { int sum = 0; for (int i = 0; i < w.size(); i++) { sum += w[i]; } if (sum < l) { return {}; } std::vector<std::pair<int, int>> indices; for (int i = 0; i < w.size(); i++) { indices.push_back(std::make_pair(w[i], i)); } if (indices[0].first > u) { return {}; } std::sort(indices.begin(), indices.end()); int cursum = 0, longest = 0; for (int i = 0; i < indices.size(); i++) { cursum += indices[i].first; if (cursum >= l) { cursum -= indices[i].first, longest = i; break; } } for (int i = longest; i < indices.size(); i++) { cursum += indices[i].first; cursum -= indices[i - longest].first; if (cursum >= l && cursum <= u) { std::vector<int> answer; for (int j = i; j >= i - longest + 1; j--) { answer.push_back(indices[j].second); } return answer; } } return {}; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:5:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 |    for (int i = 0; i < w.size(); i++) {
      |                    ~~^~~~~~~~~~
molecules.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < w.size(); i++) {
      |                     ~~^~~~~~~~~~
molecules.cpp:18:10: error: 'sort' is not a member of 'std'
   18 |     std::sort(indices.begin(), indices.end());
      |          ^~~~
molecules.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < indices.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
molecules.cpp:27:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = longest; i < indices.size(); i++) {
      |                           ~~^~~~~~~~~~~~~~~~