Submission #654827

#TimeUsernameProblemLanguageResultExecution timeMemory
654827sandry24Detecting Molecules (IOI16_molecules)C++17
46 / 100
5 ms596 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second

vi find_subset(int l, int u, vi w){
    vector<pi> a;
    for(int i = 0; i < w.size(); i++)
        a.pb(mp(w[i], i));
    sort(a.begin(), a.end());
    int sum = 0, left = -1, right = -1;
    for(int i = 0; i < w.size(); i++){
        if(sum + a[i].f <= u){
            sum += a[i].f;
            right = i; left = 0;
        }
        else break;
    }
    if(l == -1)
        return {};
    while(sum < l && right != w.size()-1){
        sum -= a[left].f;
        sum += a[right+1].f;
        right++; left++;
    }
    if(sum < l)
        return {};
    vi ans;
    for(int i = left; i <= right; i++)
        ans.pb(a[i].s);
    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'vi find_subset(int, int, vi)':
molecules.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i < w.size(); i++)
      |                    ~~^~~~~~~~~~
molecules.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0; i < w.size(); i++){
      |                    ~~^~~~~~~~~~
molecules.cpp:27:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while(sum < l && right != w.size()-1){
      |                      ~~~~~~^~~~~~~~~~~~~
#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...