581B Codeforces - Luxurious Houses


581B Codeforces - Luxurious Houses






Solution in C++


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

int n,m,mx,t;
map<int,int> all,nn,tax;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int nn[n];
    for(int i=0;i<n;i++)cin>>t,nn[i]=t;
    all[n-1]=nn[n-1];
    for(int i=n-2;i>=0;i--)
    {
        if(nn[i]<=all[i+1])tax[i]=1;
        all[i]=max(all[i+1],nn[i]);
    }
    for(int i=0;i<n;i++)cout<<all[i]-nn[i]+tax[i]<<" ";
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

1 التعليقات: