ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

No subject
Posted by asdfg 16 Mar 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
Posted by German Andosov 22 Mar 2020 21:19
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.