17862022-12-03 15:28:03kovacs.peter.18fBenzinkút üzemeltetés (55)cpp11Forditási hiba
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

struct point {
    int benefit = 0, distance = 0, last_index = 0;
};

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K, T, H;
    cin >> N >> K;
    vector<point> dpS(1000001);
    for (int i = 0, index = 1; i < N; i++) {
        cin >> T >> H;
        while (index <= T) {
            dpS[index] = dpS[index - 1];
            ++index;
        }
        if (T >= K && dpS[T - K].benefit + H > dpS[T].benefit) {
            dpS[T] = { dpS[T - K].benefit + H, T, i };
        }
        else if (H > dpS[T].benefit) {
            dpS[T] = { H, T, i };
        }
    }
    stack<point> answerS;
    answerS.push(dpS[T]);
    while (answerS.top().distance > K) {
        answerS.push(dpS[answerS.top().distance - K]);
    }
    cout << dpS[T].benefit << '\n' << answerS.size() << " ";
    while (!answerS.empty()) {
        cout << answerS.top().last_index + 1 << " ";
        answerS.pop();
    }
    cout << '\n';
}
Forditási hiba
exit status 1
main.cpp: In function 'int main()':
main.cpp:25:53: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<point>, point>::value_type' {aka 'point'} and '<brace-enclosed initializer list>')
   25 |             dpS[T] = { dpS[T - K].benefit + H, T, i };
      |                                                     ^
main.cpp:7:8: note: candidate: 'point& point::operator=(const point&)'
    7 | struct point {
      |        ^~~~~
main.cpp:7:8: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const point&'
main.cpp:7:8: note: candidate: 'point& point::operator=(point&&)'
main.cpp:7:8: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'point&&'
main.cpp:28:32: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<point>, point>::value_type' {aka 'point'} and '<brace-enclosed initializer list>')
   28 |             dpS[T] = { H, T, i };
      |                     ...