Custom input gives correct result

I am stuck on an easy question and I don’t know what the error is in my code.

#include<bits/stdc++.h>
using namespace std;

int main(){

int n,max=-1000000000;
std::cin>>n;
std::vector<int> vec;
int temp;
while(cin>>temp){
	vec.push_back(temp);
}
for(int i = 0 ; i < n ; i++){
	if(vec[i] > max ) max=vec[i];

}


std::cout<<max;


return 0;

}

with custom input it works fine.

hello @A18LPN0001
image
initialise ur max with value less than highlighted value

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.