Submission #321793

# Submission time Handle Problem Language Result Execution time Memory
321793 2020-11-13T11:42:56 Z nikatamliani Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
int find_subset(int l, int u, int w[], int n, int result[]) {
    vector<int> indices(n);
    for(int i = 0; i < n; ++i) {
        indices[i] = i; 
    }
    sort(indices.begin(), indices.end(), [&](int x, int y) {
        return w[x] > w[y];
    });
    #define ll long long
    ll sum = 0, cnt = 0, save = 0;
    for(int i = 0; i < n; ++i) {
        int index = indices[i]; 
        sum += w[index];
        result[cnt++] = index; 
        if(sum >= l) {
            save = i + 1;
            break;
        }
    }
    int ptr = 0; 
    while(save < n && sum > u) {
        sum -= result[ptr];
        result[ptr++] = indices[save++];
        sum += result[ptr];
    }
    if(sum <= u) {
        assert(sum >= l);
        return 1;
    }
    return 0;
}
// int main() {
//     int l, u, n;
//     cin >> l >> u >> n;
//     int w[n], result[n];
//     for(int i = 0; i < n; ++i) {
//         cin >> w[i];
//     }
//     cout << find_subset(l, u, w, n, result) << '\n';
//     for(int i = 0; i < n; ++i) {
//         cout << result[i] << ' ';
//     }
// }

Compilation message

/tmp/ccZ7vI6s.o: In function `main':
grader.cpp:(.text.startup+0x139): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status