Submission #54134

# Submission time Handle Problem Language Result Execution time Memory
54134 2018-07-02T12:55:35 Z WLZ Detecting Molecules (IOI16_molecules) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

void find_subset(int n, int l, int u, int w[]) {
  vector< pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    v.emplace_back(w[i], i);
  }
  sort(v.begin(), v.end());
  int i = 0, j = 0;
  long long cur = 0ll;
  vector<int> was(n, 0);
  int cnt = 0;
  for (;;) {
    while (i < n && cur < (long long) l) {
      was[v[i].second] = 1;
      cur += (long long) v[i++].first;      
      cnt++;
    }
    while (j < n && cur > (long long) u) {
      was[v[j].second] = 0;
      cur -= (long long) v[j++].first;
      cnt--;
    }
    if (cur >= l && cur <= u) {
      cout << cnt << '\n';
      int first = 1;
      for (int i = 0; i < n; i++) {
        if (was[i]) {
          if (first) {
            first = 0;
          } else {
            cout << ' ';
          }
          cout << i;
        }
      }
      return;
    }
    if (i >= n || j >= n) {
      break;
    }
  }
  cout << "0\n";
  return;
} 

int main() {
  int n;
  int l, u;
  cin >> n >> l >> u;
  int w[200005];
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  find_subset(n, l, u, w);
  return 0;
}

Compilation message

/tmp/ccJGDouR.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cczybMRl.o:molecules.cpp:(.text.startup+0x0): first defined here
/tmp/ccJGDouR.o: In function `main':
grader.cpp:(.text.startup+0x152): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status