I am a 10th grade student have just started competitive programming. I was recently was solving this.
While trying to solve this question I encountered this error.
prog.cpp:32:43: error: invalid types ‘[int*]’ for array subscript std::swap(a[p], *std::min_element[b,b+n]); ^ I tried to find a solution but have been stuck on this problem for almost a day.
This is my code:
#include <iostream>
#include <list>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k,a[100005]={0},b[100005]={0};
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
sort(a,a+n);
sort(b,b+n);
int one = 0, two = 0, p = n - 1, j = n - 1;
for ( k>=0;k--) {
if(k==0){
cout<<*std::max_element(a,a+n)+*std::min_element(b,b+n)<< "\n";
}
if (a[p]>b[j]) {
std::swap(b[j], *std::min_element[a,a+n]);
j--;
one++;
}
if (a[p]<b[j]) {
std::swap(a[p], *std::min_element[b,b+n]);
p--;
two++;
}
}
return (0);
}
I would really appreciate if som eone would tell me what I am doing wrong. Also, please point out to anyways I can make my code better.