제출 #577876

#제출 시각아이디문제언어결과실행 시간메모리
577876Trisanu_DasArt Exhibition (JOI18_art)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<pair<int, int>> a(n); for (auto p : a) cin >> p.first >> p.second; sort(a.begin(), a.end()); int pref[n + 1]; for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + a[i][1]; vector diff(pref + 1, pref + n + 1); for (int i = 0; i < n; i++) diff[i] -= a[i][0]; long ans = 0, tmp = INT_MIN / 2; for (int i = n - 1; i > -1; i--) { tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i][0] - pref[i]); } cout << ans << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

art.cpp: In function 'int main()':
art.cpp:10:61: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   10 |     for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + a[i][1];
      |                                                             ^
art.cpp:12:48: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   12 |     for (int i = 0; i < n; i++) diff[i] -= a[i][0];
      |                                                ^
art.cpp:16:31: error: no matching function for call to 'max(long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   16 |         tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i][0] - pref[i]);
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from art.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
art.cpp:16:31: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   16 |         tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i][0] - pref[i]);
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from art.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
art.cpp:16:31: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   16 |         tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i][0] - pref[i]);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from art.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
art.cpp:16:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   16 |         tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i][0] - pref[i]);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from art.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
art.cpp:16:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   16 |         tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i][0] - pref[i]);
      |                               ^
art.cpp:16:59: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   16 |         tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i][0] - pref[i]);
      |                                                           ^