#2087
Se consideră un număr natural k și două tablouri unidimensionale A și B, cu n respectiv m elemente, numere întregi, sortate crescător. Să se afișeze primele k perechi de numere de sumă minimă. Fiecare pereche conține un număr din A, un număr din B.
| Problema | Kminsum | Operații I/O |
kminsum.in/kminsum.out
|
|---|---|---|---|
| Limita timp | 0.02 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #63332915 | Utilizator | |
| Fișier | kminsum.cpp | Dimensiune | 943 B |
| Data încărcării | 26 Februarie 2026, 15:20 | Scor/rezultat | Eroare de compilare |
kminsum.cpp: In function 'int main()': kminsum.cpp:20:32: error: converting to 'std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int> >, std::greater<std::tuple<int, int, int> > >::value_type {aka std::tuple<int, int, int>}' from initializer list would use explicit constructor 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int, int, int}; <template-parameter-2-2> = void; _Elements = {int, int, int}]' pq.push({A[0] + B[0], 0, 0}); ^ kminsum.cpp:24:14: error: expected unqualified-id before '[' token auto [s, i, j] = pq.top(); pq.pop(); ^ kminsum.cpp:25:19: error: 'i' was not declared in this scope fout << A[i] << " " << B[j] << "\n"; ^ kminsum.cpp:25:34: error: 'j' was not declared in this scope fout << A[i] << " " << B[j] << "\n"; ^ kminsum.cpp:27:49: error: no matching function for call to 'std::set<std::pair<int, int> >::count(<brace-enclosed initializer list>)' if (i + 1 < n && !visited.count({i+1, j})) { ^ kminsum.cpp:27:49: note: candidate is: In file included from /usr/include/c++/4.8/set:61:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_set.h:644:7: note: std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::size_type = unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>] count(const key_type& __x) const ^ /usr/include/c++/4.8/bits/stl_set.h:644:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type& {aka const std::pair<int, int>&}' kminsum.cpp:28:44: error: no matching function for call to 'std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int> >, std::greater<std::tuple<int, int, int> > >::push(<brace-enclosed initializer list>)' pq.push({A[i+1] + B[j], i+1, j}); ^ kminsum.cpp:28:44: note: candidates are: In file included from /usr/include/c++/4.8/queue:64:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:85, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_queue.h:496:7: note: void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::tuple<int, int, int>; _Sequence = std::vector<std::tuple<int, int, int> >; _Compare = std::greater<std::tuple<int, int, int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::tuple<int, int, int>] push(const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_queue.h:496:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::tuple<int, int, int>&}' /usr/include/c++/4.8/bits/stl_queue.h:504:7: note: void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::tuple<int, int, int>; _Sequence = std::vector<std::tuple<int, int, int> >; _Compare = std::greater<std::tuple<int, int, int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::tuple<int, int, int>] push(value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_queue.h:504:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int> >, std::greater<std::tuple<int, int, int> > >::value_type&& {aka std::tuple<int, int, int>&&}' kminsum.cpp:29:36: error: no matching function for call to 'std::set<std::pair<int, int> >::insert(<brace-enclosed initializer list>)' visited.insert({i+1, j}); ^ kminsum.cpp:29:36: note: candidates are: In file included from /usr/include/c++/4.8/set:61:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_set.h:460:7: note: std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:460:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}' /usr/include/c++/4.8/bits/stl_set.h:469:7: note: std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:469:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}' /usr/include/c++/4.8/bits/stl_set.h:497:7: note: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(const_iterator __position, const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:497:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_set.h:502:7: note: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(const_iterator __position, value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:502:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_set.h:517:2: note: template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >] insert(_InputIterator __first, _InputIterator __last) ^ /usr/include/c++/4.8/bits/stl_set.h:517:2: note: template argument deduction/substitution failed: kminsum.cpp:29:36: note: candidate expects 2 arguments, 1 provided visited.insert({i+1, j}); ^ In file included from /usr/include/c++/4.8/set:61:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_set.h:529:7: note: void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >] insert(initializer_list<value_type> __l) ^ /usr/include/c++/4.8/bits/stl_set.h:529:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<std::pair<int, int> >' kminsum.cpp:31:49: error: no matching function for call to 'std::set<std::pair<int, int> >::count(<brace-enclosed initializer list>)' if (j + 1 < m && !visited.count({i, j+1})) { ^ kminsum.cpp:31:49: note: candidate is: In file included from /usr/include/c++/4.8/set:61:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_set.h:644:7: note: std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::size_type = unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>] count(const key_type& __x) const ^ /usr/include/c++/4.8/bits/stl_set.h:644:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type& {aka const std::pair<int, int>&}' kminsum.cpp:32:44: error: no matching function for call to 'std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int> >, std::greater<std::tuple<int, int, int> > >::push(<brace-enclosed initializer list>)' pq.push({A[i] + B[j+1], i, j+1}); ^ kminsum.cpp:32:44: note: candidates are: In file included from /usr/include/c++/4.8/queue:64:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:85, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_queue.h:496:7: note: void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::tuple<int, int, int>; _Sequence = std::vector<std::tuple<int, int, int> >; _Compare = std::greater<std::tuple<int, int, int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::tuple<int, int, int>] push(const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_queue.h:496:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::tuple<int, int, int>&}' /usr/include/c++/4.8/bits/stl_queue.h:504:7: note: void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::tuple<int, int, int>; _Sequence = std::vector<std::tuple<int, int, int> >; _Compare = std::greater<std::tuple<int, int, int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::tuple<int, int, int>] push(value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_queue.h:504:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int> >, std::greater<std::tuple<int, int, int> > >::value_type&& {aka std::tuple<int, int, int>&&}' kminsum.cpp:33:36: error: no matching function for call to 'std::set<std::pair<int, int> >::insert(<brace-enclosed initializer list>)' visited.insert({i, j+1}); ^ kminsum.cpp:33:36: note: candidates are: In file included from /usr/include/c++/4.8/set:61:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_set.h:460:7: note: std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:460:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}' /usr/include/c++/4.8/bits/stl_set.h:469:7: note: std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:469:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}' /usr/include/c++/4.8/bits/stl_set.h:497:7: note: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(const_iterator __position, const value_type& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:497:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_set.h:502:7: note: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>] insert(const_iterator __position, value_type&& __x) ^ /usr/include/c++/4.8/bits/stl_set.h:502:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/stl_set.h:517:2: note: template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >] insert(_InputIterator __first, _InputIterator __last) ^ /usr/include/c++/4.8/bits/stl_set.h:517:2: note: template argument deduction/substitution failed: kminsum.cpp:33:36: note: candidate expects 2 arguments, 1 provided visited.insert({i, j+1}); ^ In file included from /usr/include/c++/4.8/set:61:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:86, from kminsum.cpp:1: /usr/include/c++/4.8/bits/stl_set.h:529:7: note: void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >] insert(initializer_list<value_type> __l) ^ /usr/include/c++/4.8/bits/stl_set.h:529:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<std::pair<int, int> >'
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Kminsum 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ă.