Submission #112332

# Submission time Handle Problem Language Result Execution time Memory
112332 2019-05-18T18:36:13 Z ioilolcom Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	vector<pair<int,int> > ww;
	for(int i=0; i<(int)w.size(); i++) {
		ww.push_back({w[i],i});
	}
	sort(ww.begin(),ww.end());
	vector<int> ans;
	int a=0;
	int r=0;
	int n=(int)w.size();
	ll sum=0;
	while(r<n&&a<n) {
		sum+=ww[r].x;
		//cout<<sum<<endl;
		while(sum>u) {
			sum-=w[a].x;
			a++;
		}
		if(sum>=l&&sum<=u) {
			for(int i=a; i<=r; i++) {
				ans.push_back(ww[i].y);
			}
			return ans;
		}
		r++;
	}
	return std::vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:18:14: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> > >::value_type {aka struct std::pair<int, int>}' has no member named 'x'
   sum+=ww[r].x;
              ^
molecules.cpp:21:14: error: request for member 'x' in 'w.std::vector<int>::operator[](((std::vector<int>::size_type)a))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
    sum-=w[a].x;
              ^
molecules.cpp:26:25: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> > >::value_type {aka struct std::pair<int, int>}' has no member named 'y'
     ans.push_back(ww[i].y);
                         ^