Language: C++

#include<bits/stdc++.h>
using namespace std;
double algo(int x);
unordered_map<int,double> p;
int main(){
int n,k,i,j;
double max_sum=-DBL_MAX;
cin>>n>>k;
vector<int> v(n,0);
for(i=0;i<n;i++) cin>>v[i]; 
for(i=0;i<=n-k;i++){
  double sum=0;
	for(j=0;j<k;j++){
      if(p.find([v[j+i]])!=p.end())
         sum+=p[v[j+i]]->second;
      else
		sum+=algo(v[j+i]);
	}
  if(sum>max_sum)
    max_sum = sum;
}
  
cout<<max_sum;
  
  
}

double algo(int x){
  double value=(x+1)/2;
  p[x]=value;
  return value;
}  
  


Compiler output:
a.cc: In function 'int main()':
a.cc:14:19: error: expected ',' before '[' token
   14 |       if(p.find([v[j+i]])!=p.end())
      |                   ^
      |                   ,
a.cc:14:19: error: expected identifier before '[' token
a.cc: In lambda function:
a.cc:14:25: error: expected '{' before ')' token
   14 |       if(p.find([v[j+i]])!=p.end())
      |                         ^
a.cc: In function 'int main()':
a.cc:14:16: error: no matching function for call to 'std::unordered_map<int, double>::find(main()::<lambda()>)'
   14 |       if(p.find([v[j+i]])!=p.end())
      |          ~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/unordered_map.h:876:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::find(const key_type&) [with _Key = int; _Tp = double; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, double> >; iterator = std::__detail::_Insert_base<int, std::pair<const int, double>, std::allocator<std::pair<const int, double> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator; key_type = int]'
  876 |       find(const key_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/unordered_map.h:876:28: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'const std::unordered_map<int, double>::key_type&' {aka 'const int&'}
  876 |       find(const key_type& __x)
      |            ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/unordered_map.h:887:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::find(const key_type&) const [with _Key = int; _Tp = double; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, double> >; const_iterator = std::__detail::_Insert_base<int, std::pair<const int, double>, std::allocator<std::pair<const int, double> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::const_iterator; key_type = int]'
  887 |       find(const key_type& __x) const
      |       ^~~~
/usr/include/c++/14/bits/unordered_map.h:887:28: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'const std::unordered_map<int, double>::key_type&' {aka 'const int&'}
  887 |       find(const key_type& __x) const
      |            ~~~~~~~~~~~~~~~~^~~
a.cc:15:24: error: base operand of '->' is not a pointer
   15 |          sum+=p[v[j+i]]->second;
      |                        ^~