Submission #737275

#TimeUsernameProblemLanguageResultExecution timeMemory
737275AmaarsaaDetecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms212 KiB
#include "molecules.h"
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
vector<int> find_subset(int l, int u,  vector<int> w) {
	ll p, sum, s, j, r, i;
	sort (w.begin(), w.end());
	
	s = 0;
	r = w.size();
	ll a[r + 2];
	a[0] = w[0];
	for ( i = 1; i < w.size(); i ++) {
		a[i] = a[i - 1] + w[i];
	}
	vector < int > Ans;
	Ans.clear();
	for (i = 0; i < w.size(); i ++) {
		p = upper_bound(w.begin(), w.end(), w[i] + (u - l)) - w.begin();
		p --;
		sum = a[p] - a[i] + w[i];
		while (sum > u) {
			sum -= w[p];
			p --;
		}
		if (sum >= l && sum <= u) {
			for ( j = i; j <= p; j ++) {
				Ans.push_back(w[j]);
			}
			break;
		}
	}
	return Ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for ( i = 1; i < w.size(); i ++) {
      |               ~~^~~~~~~~~~
molecules.cpp:19:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for (i = 0; i < w.size(); i ++) {
      |              ~~^~~~~~~~~~
molecules.cpp:7:13: warning: variable 's' set but not used [-Wunused-but-set-variable]
    7 |  ll p, sum, s, j, r, i;
      |             ^
#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...