Maths Result

what is wrong in this or may be i didn’t understand the question compeletly??

#include<iostream>
using namespace std;
   long long arr[100000000];
int main()
{
    int n;
    cin>>n;
 
    for(int i=0;i<n;i++)
    cin>>arr[i];
    for(int i=n-1;i>=0;i--)
    {
        if(arr[i]>arr[i-1])
        arr[i-1]=arr[i];
    }
    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
} ```

What question?

3 Likes
1 Like

Mistakes:-
1.Size of array is 1e8 , which will give rte.
2.logic is wrong.
Input :
5
1 2 3 4 5
Your output:
5 5 5 5 5
Correct Output:
2 3 4 5 5

5 Likes

It is still unclear to me why your example should output 2 3 4 5 5. The statement presumes that any student should have a higher or equal mark than some other student after him. In your case, isn’t the first student with only 2 marks breaking this rule (as the one after him have 3, 4 or 5 marks)?

Also, why isn’t 5 5 5 5 5 a valid answer? It doesn’t state that we should minimize the sum of differences between the old marks and new marks.

Can you provide a better insight on this problem?