Submission #416959

#TimeUsernameProblemLanguageResultExecution timeMemory
416959DEQKDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 100100;

int find_subset(int l,int u, vector<int> w, int n, vector<int> result) {
	vector<pair<int, int>> a(n);
	vector<ll> pref = {0};
	for(int i = 0; i < n; i++) {
		a[i] = {w[i], i};
	}
	sort(a.begin(), a.end());
	for(int i = 0; i < n; i++) {
		pref.push_back(pref.back() + a[i].first);
	}
	int ans = -1;
	for(int i = 0; i < n; i++) {
		int j = lower_bound(pref.begin(), pref.end(), pref[i] + l) - pref.begin();
		if(j < pref.size() && pref[j] - pref[i] <= r) {
			ans = 0;
			for(i++; i <= j; i++) {
				result.push_back(a[i].second);
				ans++;
			}
			break;
		}
	}
	return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'int find_subset(int, int, std::vector<int>, int, std::vector<int>)':
molecules.cpp:20:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   if(j < pref.size() && pref[j] - pref[i] <= r) {
      |      ~~^~~~~~~~~~~~~
molecules.cpp:20:46: error: 'r' was not declared in this scope
   20 |   if(j < pref.size() && pref[j] - pref[i] <= r) {
      |                                              ^