1787 | 2022-12-03 15:28:40 | kovacs.peter.18f | Benzinkút üzemeltetés (55) | cpp11 | Compilation error |
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
struct place {
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<place> 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<place> 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';
}
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<place>, place>::value_type' {aka 'place'} and '<brace-enclosed initializer list>')
25 | dpS[T] = { dpS[T - K].benefit + H, T, i };
| ^
main.cpp:7:8: note: candidate: 'place& place::operator=(const place&)'
7 | struct place {
| ^~~~~
main.cpp:7:8: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const place&'
main.cpp:7:8: note: candidate: 'place& place::operator=(place&&)'
main.cpp:7:8: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'place&&'
main.cpp:28:32: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<place>, place>::value_type' {aka 'place'} and '<brace-enclosed initializer list>')
28 | dpS[T] = { H, T, i };
| ...