Submission #951300

#TimeUsernameProblemLanguageResultExecution timeMemory
951300chandu33Detecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

vector<int> find_subset(int L, int U, int[] A) {
	vector<int> ans;
	int N = A.length;
	vector<int> pos(N);
	iota(pos.begin(), pos.end(), 0); 
	sort(pos.begin(), pos.end(), [&A](int a, int b){
		return A[a] < A[b];
	});
	sort(A, A + N);
	int low = 0, high = N - 1;
	ll sum = 0;
	int i = 0, j = 0;
	for(int i = 0; i < N; i++) {
		sum += A[i];
		while(sum > U) {
			sum -= A[j++];
		}
		if(sum >= L && sum <= U) {
			for(int k = j; k <= i; k++) {
				ans.push_back(pos[k]);
			}
			break;
		}
	}
	return ans;
}

Compilation message (stderr)

molecules.cpp:4:45: error: expected ',' or '...' before 'A'
    4 | vector<int> find_subset(int L, int U, int[] A) {
      |                                             ^
molecules.cpp: In function 'std::vector<int> find_subset(int, int, int*)':
molecules.cpp:6:10: error: 'A' was not declared in this scope
    6 |  int N = A.length;
      |          ^
molecules.cpp: In lambda function:
molecules.cpp:10:10: error: 'A' is not captured
   10 |   return A[a] < A[b];
      |          ^
molecules.cpp:9:34: note: the lambda has no capture-default
    9 |  sort(pos.begin(), pos.end(), [&A](int a, int b){
      |                                  ^
molecules.cpp:6:10: note: '<typeprefixerror>A' declared here
    6 |  int N = A.length;
      |          ^
molecules.cpp:10:17: error: 'A' is not captured
   10 |   return A[a] < A[b];
      |                 ^
molecules.cpp:9:34: note: the lambda has no capture-default
    9 |  sort(pos.begin(), pos.end(), [&A](int a, int b){
      |                                  ^
molecules.cpp:6:10: note: '<typeprefixerror>A' declared here
    6 |  int N = A.length;
      |          ^
molecules.cpp: In function 'std::vector<int> find_subset(int, int, int*)':
molecules.cpp:14:2: error: 'll' was not declared in this scope
   14 |  ll sum = 0;
      |  ^~
molecules.cpp:17:3: error: 'sum' was not declared in this scope
   17 |   sum += A[i];
      |   ^~~
molecules.cpp:13:6: warning: unused variable 'low' [-Wunused-variable]
   13 |  int low = 0, high = N - 1;
      |      ^~~
molecules.cpp:13:15: warning: unused variable 'high' [-Wunused-variable]
   13 |  int low = 0, high = N - 1;
      |               ^~~~
molecules.cpp:15:6: warning: unused variable 'i' [-Wunused-variable]
   15 |  int i = 0, j = 0;
      |      ^