Submission #1292236

#TimeUsernameProblemLanguageResultExecution timeMemory
1292236chaitanyamehtaSolar Storm (NOI20_solarstorm)C++20
Compilation error
0 ms0 KiB
// #include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int ,int> #define v vector #define all(a) a.begin() , a.end() signed main(){ int n , s , k; cin>>n>>s>>k; vector<int> d(n + 1 , 0) , di(n + 1, 0); for(int i = 1 ; i <= n-1; i++){ cin>>di[i]; } v<int> v(n +1, 0) , impact(n + 1 , 0) , p(n + 1 , 0); for(int i = 1 ;i <= n ; i++)cin>>v[i]; for(int i = 1; i<=n;i++){ p[i] = p[i-1]+v[i]; } // cout << d[0] << " "; d[1] = 0; // cout << d[1] <<" "; for(int i = 2 ; i <= n ; i++){ d[i] = di[i - 1] + d[i - 1]; // cout << d[i] << " "; } // cout << "\n"; for(int i = 1 ;i<=n;i++){ int left = max(0LL , d[i] - k); int right = min(d[n] , d[i] + k); int left_idx = max(0 ,( (lower_bound(all(d) , left) - d.begin()) - 1)); int right_idx = (upper_bound(all(d) , right) - d.begin()) - 1; // cout << left_idx << " "<<right_idx << "\n"; int sum = 0; sum += p[i] - p[left_idx]; sum += p[right_idx] - p[i - 1]; impact[i] = sum - v[i]; // cout << impact[i] << " "; } cout << 1 << "\n"; int ans = max_element(impact.begin() , impact.end()) - impact.begin(); cout << ans; }

Compilation message (stderr)

SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:33:27: error: no matching function for call to 'max(int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   33 |         int left_idx = max(0 ,( (lower_bound(all(d) , left) - d.begin()) - 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from SolarStorm.cpp:2:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr 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:
SolarStorm.cpp:33:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   33 |         int left_idx = max(0 ,( (lower_bound(all(d) , left) - d.begin()) - 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr 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:
SolarStorm.cpp:33:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   33 |         int left_idx = max(0 ,( (lower_bound(all(d) , left) - d.begin()) - 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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> constexpr _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:
SolarStorm.cpp:33:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   33 |         int left_idx = max(0 ,( (lower_bound(all(d) , left) - d.begin()) - 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _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:
SolarStorm.cpp:33:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   33 |         int left_idx = max(0 ,( (lower_bound(all(d) , left) - d.begin()) - 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~