답안 #265837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
265837 2020-08-15T05:00:09 Z amalla Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
#include "molecules.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> find_subset(int l, int u, vector<int> w) {
    int N = w.size();
    vector<pair<int,int>> A(N);
    for (int i = 0; i<N; ++i) {
        A[i].first = w[i]; A[i].second = i;
    }
    sort(A.begin(), A.end());
    ll sum = 0;
    queue<int> q;
    for (int i = 0; i<N; ++i) {
        sum += A[i].first;
        q.push(A[i].second);
        while (sum>u) {
            sum -= A[q.front()];
            q.pop();
        }
        if (sum>=l) {
            vector<int> Ans(q.size());
            j = 0;
            while(!q.empty()) {
                Ans[j] = q.front(); q.pop();
                ++j;
            }
            return Ans;
        }
    }
    return vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:21:17: error: no match for 'operator-=' (operand types are 'long long int' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   21 |             sum -= A[q.front()];
molecules.cpp:26:13: error: 'j' was not declared in this scope
   26 |             j = 0;
      |             ^