|
|
вернуться в форумNo subject Послано asdfg 16 мар 2020 10:43 what's wrong with code? I get wrong answer every time. #include<bits/stdc++.h> using namespace std; int main() { int n,min=99; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } for(int j=1;j<n;j++) { int max=arr[j]-arr[j-1];
if(max<min && max>=0) { min=max; }
}
cout<<min<<endl; } Re: No subject 1) Why do you initialize min as 99? Weights can be up to 10^5. 2) This problem can't be solved so easily. It requires to examine all options (2^n in total). You can use recursive function, for example. |
|
|