#3846
După ce Ionuț a învățat despre algoritmul lui Kadane își pune următoarea întrebare: se dă N și K apoi un vector cu N elemente, din acest vector care este suma maximă a unei secvențe (elemente adiacente) de lungime cel puțin K. A zis să vă întrebe pe voi cum se face.
infoleague.net propunere runda 2 problema 2.
| Problema | KSum2 | Operații I/O |
ksum2.in/ksum2.out
|
|---|---|---|---|
| Limita timp | 0.02 secunde | Limita memorie |
Total: 16 MB
/
Stivă 8 MB
|
| Id soluție | #64469322 | Utilizator | |
| Fișier | ksum2.cpp | Dimensiune | 639 B |
| Data încărcării | 08 Mai 2026, 16:30 | Scor/rezultat | Eroare de compilare |
ksum2.cpp: In function ‘int main()’: ksum2.cpp:25:19: error: no matching function for call to ‘max(long long int&, int)’ 25 | maxx = max( maxx, s[i] - s[dq.front()]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from ksum2.cpp:1: /usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)’ 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: ksum2.cpp:25:19: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 25 | maxx = max( maxx, s[i] - s[dq.front()]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed: ksum2.cpp:25:19: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 25 | maxx = max( maxx, s[i] - s[dq.front()]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:61: /usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> _Tp std::max(initializer_list<_Tp>)’ 5795 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5795:5: note: template argument deduction/substitution failed: ksum2.cpp:25:19: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 25 | maxx = max( maxx, s[i] - s[dq.front()]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> _Tp std::max(initializer_list<_Tp>, _Compare)’ 5805 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: template argument deduction/substitution failed: ksum2.cpp:25:19: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 25 | maxx = max( maxx, s[i] - s[dq.front()]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema KSum2 face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.