Submission #1088129

#TimeUsernameProblemLanguageResultExecution timeMemory
1088129LucasLeDetecting Molecules (IOI16_molecules)C++17
69 / 100
37 ms5564 KiB
#include "molecules.h"
#include <bits/stdc++.h>
 
using namespace std;
 
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
  vector<pair<int, int>> v;
  int n = (int)w.size();
  for (int i = 0; i < n; ++i)
    v.push_back({w[i], i});
  v.push_back({INT_MAX, n});
  sort(v.begin(), v.end());
  int pref = 0, suff = 0;
  for (int i = 0; i < n; ++i) {
    pref += v[i].first;
    suff += v[n - 1 - i].first;
    if (pref <= u && suff >= l) {
      vector<int> res;
      for (int j = i; j < n; ++j) {
        if (pref >= l) {
          for (int k = j - i; k <= j; ++k)
            res.push_back(v[k].second);
          return res;
        }
        pref += v[j + 1].first - v[j - i].first;
      }
    }
  }
  return vector<int>();
}
#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...