답안 #305892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305892 2020-09-24T04:26:41 Z talant117408 Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
#include "molecules.h"

#include <bits/stdc++.h>/*

using namespace std;

vector <int> find_subset(int l, int u, vector <int> w);
int main() {
    int n, l, u;
    assert(3 == scanf("%d %d %d", &n, &l, &u));
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &w[i]));
    std::vector<int> result = find_subset(l, u, w);
    
    printf("%d\n", (int)result.size());
    for (int i = 0; i < (int)result.size(); i++)
        printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}*/


vector <int> find_subset(int l, int r, vector <int> w){
    int n = w.size();
    vector <pair<int, int>> pref(n);
    for(int i = 0; i < n; i++){
        pref[i] = {w[i], i};
    }
    sort(pref.begin(), pref.end());
    sort(w.begin(), w.end());
    for(int i = 1; i < n; i++){
        pref[i].first += pref[i-1].first;
    }
    int pl = 0, pr = 0;
    
    while(pl < n){
        int sum = pref[pr].first-(pl ? pref[pl-1].first : 0);
        vector <int> inds;
        if(l <= sum && sum <= r){
            for(int i = pl; i <= pr; i++){
                inds.push_back(pref[i].second+1);
            }
            return inds;
        }
        else if(sum > r){
            while(pl < n && sum > r){
                sum -= w[pl];
                pl++;
            }
        }
        else if(sum < l){
            while(pr+1 < n && sum < l){
                sum += w[++pr];
            }
            if(pr+1 == n && sum < l){
                return vector <int> (0);
            }
        }
    }
    
    return vector <int> (0);
}

Compilation message

molecules.cpp:22:1: error: 'vector' does not name a type
   22 | vector <int> find_subset(int l, int r, vector <int> w){
      | ^~~~~~