Submission #1026052

#TimeUsernameProblemLanguageResultExecution timeMemory
10260520npataDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms436 KiB
#include "molecules.h"
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define vec vector

std::vector<int32_t> find_subset(int32_t l, int32_t u, std::vector<int32_t> w) {
	int n = w.size();

	vec<int> wi(n);
	iota(wi.begin(), wi.end(), 0);
	sort(wi.begin(), wi.end(), [&](int i, int j) { return w[i] < w[j]; });
	sort(w.begin(), w.end());
	int k = 0;
	int sum = 0;
	while(k < w.size() && sum + w[k] <= u) {
		sum += w[k];
		k++;
	}
	if(k == w.size()) return {};

	int j = 0;
	while(j+k < n && sum < l) {
		sum += w[j+k];
		sum -= w[j];
		j++;
	}

	if(sum < l) return {};

	vec<int32_t> ans(0);
	for(int i = j; i < j+k; i++) {
		ans.push_back(wi[i]);
	}

    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int32_t, int32_t, std::vector<int>)':
molecules.cpp:18:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  while(k < w.size() && sum + w[k] <= u) {
      |        ~~^~~~~~~~~~
molecules.cpp:22:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  if(k == w.size()) return {};
      |     ~~^~~~~~~~~~~
#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...