MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Luxurious Houses/solutions.cpp:5–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using namespace std;
4
5int main(){
6 int n, max=0;
7 cin >> n; //number of houses in the capital of Berland
8 int a[n], b[n];
9
10 for(int i=0; i<n; i++){
11 cin >> a[i]; //number of floors in the i-th house
12 }
13
14 b[n-1]=0;
15 max=a[n-1]; //consider that initially the largest house is the one on the right most
16 for(int i=n-2; i>=0; i--){ //for from right to left
17 if(a[i]<=max) b[i]=max-a[i]+1; //if the current house is smaller than the one considered to be bigger so far
18 else b[i]=0, max=a[i]; //if the current house is bigger than all the previous ones
19 }
20
21 for(int i=0; i<n; i++){
22 cout << b[i] << " ";
23 }
24 return 0;
25}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected