Submission #849732

#TimeUsernameProblemLanguageResultExecution timeMemory
849732chilengamingDetecting Molecules (IOI16_molecules)C++17
0 / 100
1073 ms348 KiB
#include<bits/stdc++.h>
#include "molecules.h"

using namespace std;

vector<int> find_subset(int l, int u, vector<int> w) {
    vector<int> ans;
    vector<pair<int, int>> ww;
    int i = 0;
    for(int &a : w) {
        ww.push_back({a, i});
        i++;
    }
    sort(ww.begin(), ww.end());
    while(ww.size() && ww.back().first > u) ww.pop_back();
    int L = 0, R = 0;
    long long sum = ww[0].first;
    while(L != ww.size() - 1 || R != ww.size() - 1) {
        while(sum < l && R + 1 < ww.size()) {
            R++;
            sum += ww[R].first;
        }
        if(sum >= l && sum <= u) {
            for(int j = L; j <= R; j++) {
                ans.push_back(ww[j].second);
            }
            return ans;
        }
        while(sum > u) {
            sum -= ww[L].first;
            L++;
        }
        if(sum >= l) {
            for(int j = L; j <= R; j++) {
                ans.push_back(ww[j].second);
            }
            return ans;
        }
    }
    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:18:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(L != ww.size() - 1 || R != ww.size() - 1) {
      |           ~~^~~~~~~~~~~~~~~~
molecules.cpp:18:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(L != ww.size() - 1 || R != ww.size() - 1) {
      |                                 ~~^~~~~~~~~~~~~~~~
molecules.cpp:19:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         while(sum < l && R + 1 < ww.size()) {
      |                          ~~~~~~^~~~~~~~~~~
#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...