Submission #386575

#TimeUsernameProblemLanguageResultExecution timeMemory
386575Christopher_RdzDetecting Molecules (IOI16_molecules)C++14
100 / 100
52 ms5612 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

struct datos{
    int valor;
    int id;
};

const bool operator <(const datos&a, const datos&b){
    return a.valor < b.valor;
}

datos arre[200005];

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    int tam = w.size();
    for (int i = 0; i < tam; i++){
        arre[i].valor = w[i];
        arre[i].id = i;
    }
    sort(arre + 0, arre + tam);
    int ini = 0, fin = 0, mayor, menor;
    long long int suma = 0;
    if (l > u){
        mayor = l;
        menor = u;
    }else{
        mayor = u;
        menor = l;
    }
    bool puede = false;
    while (fin <= tam){
        if (suma < menor){
            suma += arre[fin].valor;
            fin++;
        }else{
            if (suma > mayor){
                suma -= arre[ini].valor;
                ini++;
            }else{
                if (suma >= menor and suma <= mayor){
                    puede = true;
                    break;
                }
            }
        }
    }
    vector <int> res;
    if (puede){
        suma = 0;
        for (int i = ini; i <= fin; i++){
            if (suma < menor){
                res.push_back(arre[i].id);
                suma += arre[i].valor;
            }
        }
    }
    return res;
}
#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...