Submission #880260

# Submission time Handle Problem Language Result Execution time Memory
880260 2023-11-29T04:55:43 Z Mardonbekhazratov A Plus B (IOI23_aplusb) C++17
Compilation error
0 ms 0 KB
#include "aplusb.h"

std::vector<int> smallest_sums(int N, std::vector<int> A, std::vector<int> B) {
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	int l=-1,r=1e18;
	while(r-l>1){
		int mid=(l+r)/2;
		int ans=0;
		for(int i=0;i<N;i++){
			ans+=upper_bound(B.begin(),B.end(),mid-A[i])-B.begin();
		}
		if(ans>=N) r=mid;
		else l=mid;
	}
	vector<int> ans(N);
	int j=0;
	for(int i=0;i<N;i++){
		int pos=lower_bound(B.begin(),B.end(),r-A[i])-B;
		for(int k=0;k<pos;k++){
			ans[j++]=A[i]+B[k];
		}
	}
	while(j<N) ans[j++]=r;
	sort(ans.begin(),ans.end());
	return ans;
}

Compilation message

aplusb.cpp: In function 'std::vector<int> smallest_sums(int, std::vector<int>, std::vector<int>)':
aplusb.cpp:4:2: error: 'sort' was not declared in this scope; did you mean 'short'?
    4 |  sort(A.begin(),A.end());
      |  ^~~~
      |  short
aplusb.cpp:6:13: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    6 |  int l=-1,r=1e18;
      |             ^~~~
aplusb.cpp:11:9: error: 'upper_bound' was not declared in this scope
   11 |    ans+=upper_bound(B.begin(),B.end(),mid-A[i])-B.begin();
      |         ^~~~~~~~~~~
aplusb.cpp:16:2: error: 'vector' was not declared in this scope
   16 |  vector<int> ans(N);
      |  ^~~~~~
aplusb.cpp:16:2: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from aplusb.h:1,
                 from aplusb.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from aplusb.h:1,
                 from aplusb.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
aplusb.cpp:16:9: error: expected primary-expression before 'int'
   16 |  vector<int> ans(N);
      |         ^~~
aplusb.cpp:19:48: error: no match for 'operator-' (operand types are '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'std::vector<int>')
   19 |   int pos=lower_bound(B.begin(),B.end(),r-A[i])-B;
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
      |                      |                          |
      |                      |                          std::vector<int>
      |                      __gnu_cxx::__normal_iterator<int*, std::vector<int> >
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from aplusb.h:1,
                 from aplusb.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1026:7: note: candidate: '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-(__gnu_cxx::__normal_iterator<_Iterator, _Container>::difference_type) const [with _Iterator = int*; _Container = std::vector<int>; __gnu_cxx::__normal_iterator<_Iterator, _Container>::difference_type = long int]'
 1026 |       operator-(difference_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1026:33: note:   no known conversion for argument 1 from 'std::vector<int>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'}
 1026 |       operator-(difference_type __n) const _GLIBCXX_NOEXCEPT
      |                 ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  500 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:500:5: note:   template argument deduction/substitution failed:
aplusb.cpp:19:49: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::reverse_iterator<_Iterator>'
   19 |   int pos=lower_bound(B.begin(),B.end(),r-A[i])-B;
      |                                                 ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from aplusb.h:1,
                 from aplusb.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1533:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1533 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1533:5: note:   template argument deduction/substitution failed:
aplusb.cpp:19:49: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::move_iterator<_IteratorL>'
   19 |   int pos=lower_bound(B.begin(),B.end(),r-A[i])-B;
      |                                                 ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from aplusb.h:1,
                 from aplusb.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1164:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> decltype ((__lhs.base() - __rhs.base())) __gnu_cxx::operator-(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)'
 1164 |     operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1164:5: note:   template argument deduction/substitution failed:
aplusb.cpp:19:49: note:   'std::vector<int>' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorR, _Container>'
   19 |   int pos=lower_bound(B.begin(),B.end(),r-A[i])-B;
      |                                                 ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from aplusb.h:1,
                 from aplusb.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1177:5: note: candidate: 'template<class _Iterator, class _Container> typename __gnu_cxx::__normal_iterator<_Iterator, _Container>::difference_type __gnu_cxx::operator-(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
 1177 |     operator-(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1177:5: note:   template argument deduction/substitution failed:
aplusb.cpp:19:49: note:   'std::vector<int>' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   19 |   int pos=lower_bound(B.begin(),B.end(),r-A[i])-B;
      |                                                 ^
aplusb.cpp:21:4: error: 'ans' was not declared in this scope
   21 |    ans[j++]=A[i]+B[k];
      |    ^~~
aplusb.cpp:24:13: error: 'ans' was not declared in this scope
   24 |  while(j<N) ans[j++]=r;
      |             ^~~
aplusb.cpp:25:7: error: 'ans' was not declared in this scope
   25 |  sort(ans.begin(),ans.end());
      |       ^~~