Submission #503039

#TimeUsernameProblemLanguageResultExecution timeMemory
503039amukkalirDetecting Molecules (IOI16_molecules)C++17
100 / 100
73 ms6176 KiB
#include "molecules.h"
#include <bits/stdc++.h> 
using namespace std; 
#define pii pair<int,int> 
#define se second 
#define fi first 
#define cek puts("HERE")
 
std::vector<int> find_subset(int L, int U, std::vector<int> w) {
 
    vector<int> ret; 
    vector<pii> cp; 
    for(int i=0; i<w.size(); i++) {
        cp.push_back({w[i], i}); 
    }
    sort(cp.begin(), cp.end()); 
    sort(w.begin(), w.end()); 
 
    long long cur = 0; 
    int l = 0, r = -1; 
 
//cek; 
//cout << l << " " << r << " " << w.size() << endl; 
    int n = w.size(); 
 
    while(l < n && r < n) {
       // cek; 
 
        while(cur < L && r+1 < n) {
            r++; 
            cur = cur + 1ll*cp[r].fi; 
        }
 
        if(cur >= L && cur <= U) {
            for(int i=l; i<=r; i++) ret.push_back(cp[i].se); 
            return ret; 
        }
 
        cur -= cp[l].fi; 
        l++; 
    }
 
    return ret; 
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0; i<w.size(); i++) {
      |                  ~^~~~~~~~~
#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...