Submission #701037

#TimeUsernameProblemLanguageResultExecution timeMemory
701037Doncho_BonbonchoDetecting Molecules (IOI16_molecules)C++14
100 / 100
62 ms5508 KiB
#include "molecules.h"
#include <bits/stdc++.h>
#include <vector>

typedef long long ll;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	
	std::vector<std::pair<int, int>> W;
	for( int i=0 ; i<w.size() ; i++ ) W.push_back({w[i], i});
	std::sort(W.begin(), W.end());

	int ind = 0;
	ll currSum = 0;

	int n = (int)W.size();

	for( int i=0 ; i<n ; i++ ){
		while( ind < n and currSum < l ) currSum += W[ind++].first;
		if( currSum >= l and currSum <= u ){
			std::vector<int> nas;
			for( int j = i ; j < ind ;  j++ ) nas.push_back( W[j].second );
			std::sort( nas.begin(), nas.end() );
			return nas;
		}
		currSum -= W[i].first;
	}
		
	return std::vector<int>() ;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for( int i=0 ; i<w.size() ; i++ ) W.push_back({w[i], 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...