제출 #1002560

#제출 시각아이디문제언어결과실행 시간메모리
1002560ocasuDetecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;


std::vector<int> find_subset(int l, int u, std::vector<int> z) {
    vector<pair<int,int>> w(n);
    for (int i=0; i<n; i++) w[i]={z[i],i};
    sort(w.begin(),w.end());

    int n=(int)(w.size());
    int pre=0, x=0;
    for (auto i: w){
        if (pre+i.first<l) pre+=i.first, x++;
    }
    vector<int> ans;
    if (x==0){
        return {w[0].second};
    }
    int sum=pre, nxt=x, prev=0;
    while (sum<l and nxt<n){
        sum-=w[prev].first; sum+=w[nxt].first;
        nxt++;
        prev++;
    }
    if (sum<l){
        return {};
    }

    for (int i=prev; i<nxt; i++){
        ans.push_back(w[i].second);
    }
    return ans;
    
    
}

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:7:29: error: 'n' was not declared in this scope
    7 |     vector<pair<int,int>> w(n);
      |                             ^