Submission #398045

# Submission time Handle Problem Language Result Execution time Memory
398045 2021-05-03T15:08:31 Z elgamalsalman Stove (JOI18_stove) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> a;
int	g, a, n, k;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> g[i];
	sort(g, g + n);

	for (int i = 1; i < n; i++) {
		a.push_back(g[i] - g[i - 1] - 1);
	}
	sort(a.begin(), a.end());

	int ans = n;
	for (int i = 0; i < n - k; i++) {
		ans += a[i];
	}

	cout << ans << '\n';
}

Compilation message

stove.cpp:6:8: error: conflicting declaration 'int a'
    6 | int g, a, n, k;
      |        ^
stove.cpp:5:13: note: previous declaration as 'std::vector<int> a'
    5 | vector<int> a;
      |             ^
stove.cpp: In function 'int main()':
stove.cpp:13:40: error: invalid types 'int[int]' for array subscript
   13 |  for (int i = 0; i < n; i++) cin >> g[i];
      |                                        ^
stove.cpp:17:18: error: invalid types 'int[int]' for array subscript
   17 |   a.push_back(g[i] - g[i - 1] - 1);
      |                  ^
stove.cpp:17:29: error: invalid types 'int[int]' for array subscript
   17 |   a.push_back(g[i] - g[i - 1] - 1);
      |                             ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from stove.cpp:1:
/usr/include/c++/9/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/9/bits/stl_algo.h:1884:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1970:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:4867:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
stove.cpp:14:15:   required from here
/usr/include/c++/9/bits/stl_algo.h:1849:3: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1849 |   __val = _GLIBCXX_MOVE(*__i);
      |   ^~~~~
/usr/include/c++/9/bits/stl_algo.h:1851:8: error: invalid type argument of unary '*' (have 'int')
 1851 |        *__first = _GLIBCXX_MOVE(__val);
      |        ^~~~~~~~
/usr/include/c++/9/bits/stl_algo.h:1849:3: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1849 |   __val = _GLIBCXX_MOVE(*__i);
      |   ^~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from stove.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = int; _Iterator2 = int]':
/usr/include/c++/9/bits/stl_algo.h:81:17:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1920:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1952:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1967:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:4867:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
stove.cpp:14:15:   required from here
/usr/include/c++/9/bits/predefined_ops.h:43:16: error: invalid type argument of unary '*' (have 'int')
   43 |       { return *__it1 < *__it2; }
      |                ^~~~~~
/usr/include/c++/9/bits/predefined_ops.h:43:25: error: invalid type argument of unary '*' (have 'int')
   43 |       { return *__it1 < *__it2; }
      |                         ^~~~~~
In file included from /usr/include/c++/9/bits/stl_algo.h:61,
                 from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from stove.cpp:1:
/usr/include/c++/9/bits/stl_heap.h: In instantiation of 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/9/bits/stl_algo.h:1671:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1932:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1947:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1967:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:4867:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
stove.cpp:14:15:   required from here
/usr/include/c++/9/bits/stl_heap.h:330:4: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
  330 |    _ValueType;
      |    ^~~~~~~~~~
/usr/include/c++/9/bits/stl_heap.h:332:4: error: no type named 'difference_type' in 'struct std::iterator_traits<int>'
  332 |    _DistanceType;
      |    ^~~~~~~~~~~~~
/usr/include/c++/9/bits/stl_heap.h: In instantiation of 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/9/bits/stl_algo.h:1674:19:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1932:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1947:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1967:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:4867:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
stove.cpp:14:15:   required from here
/usr/include/c++/9/bits/stl_heap.h:247:2: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
  247 |  _ValueType;
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/stl_heap.h:249:2: error: no type named 'difference_type' in 'struct std::iterator_traits<int>'
  249 |  _DistanceType;
      |  ^~~~~~~~~~~~~
/usr/include/c++/9/bits/stl_heap.h:252:7: error: invalid type argument of unary '*' (have 'int')
  252 |       *__result = _GLIBCXX_MOVE(*__first);
      |       ^~~~~~~~~
In file included from /usr/include/c++/9/bits/nested_exception.h:40,
                 from /usr/include/c++/9/exception:144,
                 from /usr/include/c++/9/ios:39,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from stove.cpp:1:
/usr/include/c++/9/bits/stl_heap.h:252:19: error: invalid type argument of unary '*' (have 'int')
  252 |       *__result = _GLIBCXX_MOVE(*__first);
      |                   ^~~~~~~~~~~~~