Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; int* a = new int[n]; int* b = new int[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } if (n == 1) cout << 0; else { m = a[n - 1]; b[n - 1] = 0; for (int i = n - 2; i >= 0; --i) { if (m < a[i]) { ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class B { int n; long h[]; void readInput() throws NumberFormatException, IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //Scanner sc = new Scann...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], f[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); f[n - 1] = a[n - 1]; f[n] = 0; for (int i = n - 2; i >= 0; i--) f[i] = max(f[i + 1], a[i]); for (int i = 0; i < n; i++) if (f[i] == a[i] && f[i + 1] != f[i]) ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = input() m = map(int, raw_input().split()) max_so_far = 0 vals = [0] * n for i in range(n - 1, -1, -1): val = 0 if max_so_far >= m[i]: val = max_so_far - m[i] + 1 vals[i] = val max_so_far = max(max_so_far, m[i]) print ' '.join(str(v) for v in vals)
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.*; public class test { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; int[] anss = new int[n]; int[] dh = new int[n]; for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); dh[n-1] = 0; anss[n-1]=0; String...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> bool upmin(T1 &x, T2 v) { if (x > v) { x = v; return true; } return false; } template <class T1, class T2> bool upmax(T1 &x, T2 v) { if (x < v) { x = v; return true; } return false; } void solve() { int N; cin >>...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int a[] = new int[n]; for(int i = 0; i < n; i++) { a[i] = scanner.nextInt(); } int b[] = new int[n+...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main{ public static void main(String[] args) throws Exception { ModScanner ms=new ModScanner(); int n=ms.nextInt(); long[] a=new long[n]; for(int i=0;i<n;i++) a[...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
''' Created on 28-Sep-2015 @author: Venkatesh ''' def read_int_list(): return [int(x) for x in raw_input().split()] def read_int(): return int(raw_input()) def print_next_max_num(houses): last_max = houses[-1] result = [0] houses.pop() for ele in houses[::-1]: if ele <= last_max: ...
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.*; import java.lang.*; import java.io.*; /* int n = scan.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = scan.nextInt(); long n = scan.nextLong(); long[] arr = new long[n]; for(int = 0; i < n; i++) arr[i] = scan.nextLong(); */ public class Main { pu...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.Scanner ; public class jkl { public static void main (String [] args){ Scanner s = new Scanner (System.in); int size = s.nextInt(); int [] a = new int [size]; int [] b = new int [size]; for (int j = 0 ; j<size ; j++){ int k = s.nex...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int n; int a[100100]; pair<int, int> p[100100]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); p[i] = make_pair(a[i], i); } sort(p, p + n); reverse(p, p + n); int len = 0; for (int i = 0; i < n - 1; i++) { while (p[...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; map<string, long long int> mapp; long long int a[1000000], b[1000000]; int main() { long long int n; cin >> n; for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int max = 0; for (long long int i = n - 1; i >= 0; i--) { if (a[i] > max) ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> int main() { int a[100005], m[100005], n, t, i, temp; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); m[n - 1] = a[n - 1]; m[n] = 0; for (i = n - 2; i >= 0; i--) { if (a[i] > m[i + 1]) m[i] = a[i]; else m[i] = m[i + 1]; } for (i = 0; i < n; i++) ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) arr = list(map(int, input().split())) maxi=0 e=[] for i in range(len(arr)): if arr[len(arr)-1-i] > maxi: maxi = arr[len(arr)-1-i] flag=len(arr)-1-i if len(arr)-1-i ==flag: e.append((arr[flag]- arr[len(arr)-1-i])) else: e.append((arr[flag]- arr[len(a...
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
# In this template you are not required to write code in main import sys inf = float("inf") #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd #from bisect import b...
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
/* / οΎŒοΎŒβ €β €β €β €β €β €β €β €β €β €β €β €γƒ  / )\β €β €β €β €β €β €β €β €β €β €β €β € Y (β €β €| ( Ν‘Β° ΝœΚ– Ν‘Β°οΌ‰β €βŒ’(β € γƒŽ (β € οΎ‰βŒ’ Y βŒ’γƒ½-く __/ | _β €ο½‘γƒŽ| γƒŽο½‘ |/ (β €γƒΌ '_δΊΊ`γƒΌ οΎ‰ β €|\ οΏ£ _δΊΊ'彑ノ β € )\β €β € q⠀⠀ / β €β €(\β € #β € / β €/β €β €β €/α½£====================D- /β €β €β €/β € \ \β €β €\ ( (β €)β €β €β €β € ) ).β €) (β €β €)β €β €β €β €β €( | / |β € /β €β €β €β €β €β € | / [_] β €β €β €β €β €[___] */ // Main Code at the Bottom import ...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.ArrayList; import java.util.Scanner; public class B { /** * @param args */ public static void main(String[] args) { Scanner x=new Scanner(System.in); int n=x.nextInt(); int arr[]=new int [n]; for(int i=0;i<n;i++){ arr[i]...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
// CoDE deVELOPed uNDEr AcE proDUcTiONS (enJOY!!!!) import java.util.*; public class Ace { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(),i,j,k,max=0; int[] ar=new int[n]; int[] br=new int[n]; for(i=0;i<n;i++) ar[i]=sc.nextInt(); max=ar[n-1];...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, l, x, z, i; cin >> n; long long a[n + 5]; map<long long, long long> mp; for (i = 1; i <= n; i++) { cin >> a[i]; } long long b[n + 5]; x = 0; for (i = n; i >= 1; i--) { x = max(a[i], x); b[i] = x; mp[b[i]]++; ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) h = list(map(int, input().split())) + [0] h_max = [0] * n res = ['0'] * n for i in range(n - 1, 0, -1): h_max[i - 1] = max(h_max[i], h[i] + 1) res[i] = str(max(h_max[i] - h[i], 0)) res[0] = str(max(h_max[0] - h[0], 0)) print(" ".join(res))
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) s=list(map(int,input().split())) s.reverse() d=s[0] a=[] for i in range(1,n): f=int(s[i]) if f <= d: k=str((d-f)+1) a.append(k) else: a.append(0) d=f a.insert(0,"0") a.reverse() for j in a: print(j,end=" ")
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) h = map(int, input().split()[::-1]) m_h = 0 res = [] for h in h: if m_h < h: res.append(0) m_h = h else: res.append(m_h - h + 1) print(" ".join(map(str, res[::-1])))
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int x[100009]; int a[100009]; int main() { int n, mx; cin >> n; for (int i = 0; i < n; ++i) cin >> x[i]; a[n - 1] = 0; mx = x[n - 1]; for (int i = n - 2; i >= 0; --i) { if (mx == x[i]) { a[i] = 1; } else if (mx < x[i]) { a[i] = 0; mx = ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; //Removed extra array public class LuxuriousHouses { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(bf.readL...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = input() h = map(int, raw_input().split()) res = [] mx = 0 while h: c = h.pop() if c > mx: res.append(0) mx = c else: res.append((mx - c) + 1) res.reverse() print ' '.join(map(str, res))
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> One(1000007); vector<int> Two(1000007); int main() { int n; int maximun = -1000007; cin >> n; for (int i = 0; i < n; i++) cin >> One[i]; for (int i = n - 1; i >= 0; i--) { if (One[i] > maximun) Two[i] = One[i]; else Two[i] = maximun...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) h = list(map(int, input().split())) maxi = h[n - 1] maxes = [0] * n maxes[n - 1] = 0 res = '' for i in range(n - 1, 0, -1): if h[i - 1] > maxi: maxi = h[i - 1] maxes[i - 1] = 0 else: maxes[i - 1] = maxi - h[i - 1] + 1 for i in range(n): res += str(maxes[i]) + ' ' ...
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) h=list(map(int,input().split())) ans=[0]*n ans[n-1]=0 maxh=h[n-1] for i in range(n-2,-1,-1): if h[i]>maxh: ans[i]=0 else: ans[i]=maxh-h[i]+1 maxh=max(maxh,h[i]) print(' '.join(map(str,ans)))
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#from time import time n = int(input()) x = list(map(int, input().split())) #start_time = time() abc = x[-1] a = [0] for i in range(2, n + 1): if x[-i] <= abc: a.append(abc - x[-i] + 1) elif x[-i] > abc: abc = x[-i] a.append(0) print(*a[::-1]) #print(time() - start_time)
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
l=lambda:map(int,raw_input().split()) n=input() h=l() a=[0]*n maxi=h[n-1] for i in range(n-2,-1,-1): if h[i]>maxi: a[i]=0 maxi=h[i] else: a[i]=maxi+1-h[i] for v in a: print v,
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) l=[int(x) for x in input().split()] g=[] h=0 for i in range(n-1, -1, -1): x=max(0, h+1-l[i]) h=max(h, l[i]) g.append(x) g=g[::-1] print(*g)
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int n, i, m, s; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; m = a[n]; a[n] = 0; for (i = n - 1; i > 0; i--) { s = m + 1 - a[i]; m = max(m, a[i]); a[i] = s < 0 ? 0 : s; } for (i = 1; i <= n; i++) printf("%d%c", a[i]...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class LuxoriousHouses { public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int []max=...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.*; public class test { public static void main (String[] args) throws IOException { Scanner sc = new Scanner(System.in); OutputStream out = new BufferedOutputStream ( System.out ); int n = sc.nextInt(...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> int a[100005], b[100005]; int main() { int n, max, l; scanf("%d", &n); int i; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } max = 0; for (i = n - 1; i >= 0; i--) { l = 1; if (a[i] > max) { max = a[i]; l = 0; } b[i] = max - a[i] + l; } for (i =...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double pi = acos(-1); int a[100010], d[100010], flag[100010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) scanf("%d", &a[i]); d[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; i--) { if (d[i + 1] >= a[i]) { d[i...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, max = 0; cin >> n; int a[n], h[n]; for (int i = 0; i < n; i++) cin >> a[i]; h[n - 1] = 0; for (int i = n - 2; i >= 0; i--) { if (a[i + 1] > max) { max = a[i + 1]; h[i] = max; } else { h[i] = max; } } for (int...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class P581B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); ...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
# -*- coding:utf-8 -*- import sys import math def some_func(): """ """ n = input() max =0 cache = [] n_list = map(int,sys.stdin.readline().split()) for v in n_list[::-1]: if v>max: cache.append(0) max=v elif v ==max: cache.append(1) ...
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; int a[MAXN]; int n, maxx; int ans[MAXN]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); reverse(a + 1, a + 1 + n); maxx = 0; for (int i = 1; i <= n; ++i) { if (a[i] > maxx) ans[n - i + 1] = 0;...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; public class Building { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String S[] = br.readL...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100005; int h[N], ans[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", h + i); } for (int mx = 0, i = n; i >= 1; --i) { if (mx >= h[i]) ans[i] = mx - h[i] + 1; mx = max(mx, h[i]); } for (int i = 1; i...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int n; int h[100100], b[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (0 & 1) freopen("input", "r", stdin); if (0 & 2) freopen("output", "w", stdout); cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = n - 1; i ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int h[n]; for (int i = 0; i < n; i++) cin >> h[i]; int z = 0; vector<int> ans; for (int i = n - 1; i >= 0; i--) { if (z == h[i]) { ans.push_back(1); continue; } z = max(z, h[i]); if (z - h[i] != 0) ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int n, arr[100000], r, arr1[100000], z; bool boo[100000]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> r; arr[i] = r; } for (int i = 0; i < n; i++) arr1[i] = arr[i]; reverse(arr1, arr1 + n); z = arr1[0]; boo[0] = 1; for (int i = 0; i <...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) arr = list(map(int, input().split())) maxArr = arr.copy() maxArr.reverse() maxArr[0] = maxArr[0] * -1 for i in range(1, len(arr)): if maxArr[i] > abs(maxArr[i-1]): maxArr[i] = maxArr[i] * -1 else: maxArr[i] = abs(maxArr[i-1]) maxArr.reverse() resultArr = [] for i in range(len...
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m[100000], mn[100000], mx; cin >> n; for (int i = 0; i < n; ++i) cin >> m[i]; reverse(m, m + n); mn[0] = 0, mx = m[0]; for (int i = 1; i < n; i++) if (m[i] > mx) mn[i] = 0, mx = m[i]; else mn[i] = mx - m[i] + 1; for (int...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int n, i, m; int b[100001]; int a[100001]; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; m = a[n - 1]; for (i = n - 2; i >= 0; i--) { if (m >= a[i]) b[i] = m - a[i] + 1; if (m < a[i]) m = a[i]; } for (i = 0; i < n; i++) cout << b[i] << ' ';...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) arr=list(map(int,input().split())) dp=[0]*(n+1) dp[-1]=-1; for i in range(n-1,-1,-1): maxx=max(dp[i+1],arr[i]) dp[i]=maxx #print(*dp) ans=[] for i in range(n): if arr[i]>dp[i+1]:ans.append(0) else:ans.append(dp[i+1]-arr[i]+1) print(*ans)
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), m(n); for (int& x : a) cin >> x; m[n - 1] = 0; for (int i = n - 2; i >= 0; --i) m[i] = max(a[i + 1], m[i + 1]); for (int i = 0; i < n; ++i) cout << (a[i] > m[i] ? 0 : m[i] - a[i] + 1) << ' '; }
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.Scanner; public class LuxuriousHouses { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = scan.nextInt(); int max = a[n-1]; int[] h = new int[n]; for(int i = n-2; i >= 0; i--){...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) a = input().split() for i in range(n): a[i] = int(a[i]) m = -1 res = [0]*n for i in range(n-1, -1, -1): if a[i] > m: res[i] = 0 else: res[i] = m + 1 - a[i] m = max(m, a[i]) for b in res: print(b, end=" ")
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class LuxuriousHouses { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader scan = new BufferedReader(new InputStreamReader(System.in)); int houses = Integer.parseInt(...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int h[maxn], mx[maxn]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", h + i); int cur = 0; for (int i = n - 1; i >= 0; --i) { mx[i] = cur; cur = max(cur, h[i]); } for (int i = 0; i < n - 1; ++i) ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf("%d", &n) == 1) { vector<int> x(n); for (int i = 0; i < n; i++) scanf("%d", &x[i]); int maxi = INT_MIN; vector<int> ans(n); for (int i = n - 1; i >= 0; --i) { if (maxi >= x[i]) { ans[i] = maxi + 1 - x[i]...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { long long int a[100005], n, i, max; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } max = a[n - 1]; a[n - 1] = 0; for (i = n - 2; i >= 0; i--) { if (max > a[i]) { a[i] = max - a[i] + 1; } else if (a[i] > max) { max = a[i...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(raw_input()) a = map(int, raw_input().split()) b = [] height = 0 for i in reversed(xrange(n)): if a[i] <= height: b.append(height - a[i] + 1) else: height = a[i] b.append(0) for x in reversed(b): print x,
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long a[N]; long long dp[N]; int main() { long long n; scanf("%lld", &n); int max_key = 0; int fg = 0; for (int i = 0; i < n; ++i) { scanf("%lld", &a[i]); } dp[n - 1] = 0; for (int i = n - 2; i >= 0; --i) { dp[i] = max(dp[i ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) a=list(map(int,input().split())) m=n-1 b=[] b.append(0) for i in range(n-2,-1,-1): if a[i]<=a[m]: b.append(a[m]+1-a[i]) else: m=i b.append(0) print(*b[::-1])
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.Scanner; public class Codeforce { public static void main(String[] args) { int n; Scanner s =new Scanner (System.in); n=s.nextInt(); int arr[]=new int [n]; for(int i=0;i<n;i++) arr[i]=s.nextInt(); s.close(); int a...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; template <class T> T _abs(T n) { return (n < 0 ? -n : n); } template <class T> T _max(T a, T b) { return (!(a < b) ? a : b); } template <class T> T _min(T a, T b) { return (a < b ? a : b); } template <class T> T sq(T x) { return x * x; } template <class T> T gcd(T a...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.util.Scanner; public class Luxurious_Houses { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; int[] ans = new int[n]; for(int i = 0; i<n; i++) { arr[i] = in.nextInt(); } int max = -1; for(int i = n-1; i >= 0...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, index = -1, max; cin >> n; int *a = new int[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { max = 0; for (int j = i + 1; j < n; j++) if (max < a[j]) max = a[j]; if (max < a[i]) cout << "0 "...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
def main(): num_of_house = int(raw_input()) house_heights = map(int, raw_input().split()) cur_max = 0 answer = [0 for i in range(num_of_house)] for i in range(num_of_house-1, -1, -1): if i < num_of_house - 1: if cur_max + 1 > house_heights[i]: answer[i] = cu...
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int n, hs[100001], ans[100001]; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> hs[i]; int maxx = 0; for (int i = n; i; --i) { ans[i] = max(maxx - hs[i] + 1, 0); maxx = max(maxx, hs[i]); } for (int i = 1; i < n; ++i) cout << ans[i] << ' '; c...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, a, Max = 0; vector<int> v; cin >> n; for (int i = 0; i < n; i++) { cin >> a; v.push_back(a); } Max = v.back(); v[v.size() - 1] = 0; for (int i = v.size() - 2; i >= 0; i--) { if (v[i] < Max) v[i] = (Max + 1) - v[i]; e...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> const int N = 1e5; int h[N], max[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", h + i); } max[n - 1] = h[n - 1]; for (int i = n - 2; i >= 0; --i) { max[i] = h[i] > max[i + 1] ? h[i] : max[i + 1]; } for (int i = 0; i < n - 1; ++i) { ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int a[400000]; void Up(int l, int r, int k, int u, int v) { if (l == r) { a[u] = v; return; } int m = (l + r) / 2; if (m >= k) Up(l, m, k, u * 2, v); else Up(m + 1, r, k, u * 2 + 1, v); a[u] = max(a[u * 2], a[u * 2 + 1]); } int main() { int n, ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) l=list(map(int,input().split()))[::-1] ma=0 ans=[] for i in range(n): if l[i]>ma: ans+=['0']; ma=l[i] else: ans+=[str(ma-l[i]+1)] print(' '.join(ans[::-1]))
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
def solve(arr): maxRight = arr[-1] arr[-1] = 0 for i in range(len(arr) - 2, - 1, - 1): if maxRight >= arr[i]: arr[i] = maxRight + 1 else: maxRight = arr[i] return arr n = input() arr = map(int,raw_input().split()) ans = arr ans = list(ans) arr = solve(arr) for i ...
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
a=int(input()) l=list(map(int,input().split())) d,c=[0]*a,l[-1] for x in range(2,a+1): d[-x]=max(0,c-l[-x]+1) c=max(c,l[-x]) print(*d)
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(raw_input()) N=map(int,raw_input().split()) a=0 b=[] for i in range(n): b.append(max(0,a+1-N[n-i-1])) a=max(a,N[n-i-1]) for i in range(n): print b[n-i-1],
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
var n = parseInt(readline()); var input = readline().split(' ').map(function (item) { return parseInt(item); }) var result = []; input.reduceRight(function (prev, curr) { if(curr > prev){ result.push(0); } else if (curr === prev) { result.push(1); } else { result.push(prev - curr + 1); } return Math.max(pre...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int a[maxn], o[maxn]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; ++i) scanf("%d", &a[i]); int _max = 0; for (int i = n - 1; i >= 0; --i) if (a[i] > _max) o[i] = 0, _max = a[i]; ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; int v[N], seg[4 * N + 1]; int a, b; void init(int r, int i, int j) { if (i == j) seg[r] = v[i]; else { init(2 * r, i, (i + j) / 2); init(2 * r + 1, (i + j) / 2 + 1, j); seg[r] = max(seg[2 * r], seg[2 * r + 1]); } } int quer...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> int maxsize = 30; using namespace std; int main() { int n; int A[100005]; cin >> n; for (int i = 1; i <= n; i++) cin >> A[i]; int m = 0; int ans[100005]; ans[n] = 0; for (int i = n - 1; i >= 1; i--) { m = max(m, A[i + 1]); ans[i] = m + 1 - A[i]; if (ans[i] < 0) ans[i...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) a=map(int,input().split(" ")) rmax=0 res=[] for x in reversed(list(a)): t = rmax - x res.append(0 if t<0 else t+1) rmax=max(x, rmax) for x in reversed(res): print(x,end=" ") print()
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(raw_input()) numbers = map(int, raw_input().split()) maxx = numbers[n - 1] numbers[n - 1] = 0 for it in xrange(n - 2, -1, -1): if numbers[it] > maxx: maxx = numbers[it] numbers[it] = 0 else: numbers[it] = maxx + 1 - numbers[it] print ' '.join(map(str, numbers))
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int a[100009]; int main() { int i, j, m, n, t, k; cin >> n; int ma = 0; for (i = 0; i < n; i++) { cin >> a[i]; } int sum = 0; int b[100009]; for (i = n - 1, j = 0; i >= 0; i--) { if (a[i] > ma) { ma = a[i]; b[j++] = 0; continue; ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int maxn = 100005; const int maxm = 10005; int h[maxn], ans[maxn]; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; } int maxh = 0; for (int i = n; i >= 1; i--) { if (...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int mx, n, ara[1000000]; int main() { scanf("%d", &(n)); for (int i = (0); i < (n); i++) scanf("%d", &(ara[i])); mx = ara[n - 1]; for (int i = (n - 2); i >= (0); i--) { if (mx >= ara[i]) ara[i] = mx - ara[i] + 1; else { mx = ara[i]; ara[i] ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.Reader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; impor...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double pi = acos(-1.0); const double eps = 1e-9; int n, a[200100], m[200100]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i >= 1; i--) m[i] = max(m[i + 1], a[i]); for (int i = 1; i <= n; i++) { ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int maxi[100000 + 100]; bool mark[100000 + 100]; int main() { int n; cin >> n; int h[n]; for (int i = 0; i < n; i++) cin >> h[i]; maxi[n - 1] = h[n - 1]; mark[n - 1] = true; for (int i = n - 2; i >= 0; i--) { if (h[i] > maxi[i + 1]) { maxi[i] = h[i];...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(raw_input()) a=map(int,raw_input().split(' ')) m=0 b=[0]*n m=a[-1] for i in xrange(len(a)-2,-1,-1): if(a[i]<=m): b[i]=m-a[i]+1 else: m=a[i] for i in b: print i,
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Gots { public static long mod = 1000000000 + 7; public static long gcd(long a, long b) { return (b == 0) ? a : gcd(b, a % b); } public static int counter = 0...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(input()) z=list(map(int,input().split())) lst=[0]*n;m=z[-1];lst[-1]=0 for i in range(n-2,-1,-1): if z[i] > m: lst[i]=0 m = z[i] else: lst[i]= m-z[i]+1 print(*lst)
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) a = list(map(int, input().split())) maxi = -1 for i in range(n - 1, -1, -1): t = a[i] if a[i] > maxi: a[i] = 0 else: a[i] = maxi - a[i] + 1 maxi = max(maxi, t) print(*a)
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> v(n), s(n); for (int i = 0; i < n; i++) cin >> v[i], s[i] = v[i]; reverse(s.begin(), s.end()); long long mx = 0; for (int i = 0; i < n; i++) s[i] = max(s[i], mx), mx = s[i]; reverse(s.begin(), s.end()); ...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n = int(input()) h = list(map(int, input().split())) a = [0]*n m = -1 for i in range(n-1,-1,-1): a[i] = max(m+1-h[i],0) m = max(m, h[i]) print(*a)
PYTHON3
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; long long int a[1000000], b[1000000], n, k, l, x, m, s, p, i, j, t; int main() { map<long long, long long> v; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; v[a[i]]++; } for (i = 0; i < n; i++) b[i] = a[i]; sort(b, b + n); reverse(b, b + n); m = b[...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; public class a { public static void main(Strin...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { vector<int> h, ans; int n, t = 0; ios::sync_with_stdio(false); cin.tie(0); cin >> n; h.resize(n + 1); for (int i = 1; i <= n; i++) cin >> h[i]; ans.push_back(0); t = h[n]; for (int i = n - 1; i > 0; i--) { if (h[i] > t) ans.push_ba...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int a[100005]; int suff[100005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = n; i >= 1; i--) { suff[i] = max(suff[i + 1], a[i]); } for (int i = 1; i <= n; i++) { printf("%d ", max(0, suff[i...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
num = int(raw_input()) houses = [int(x) for x in raw_input().split()] maxAt = [0] * num highest = 0 for i in range(num-1, -1, -1): if houses[i] > highest: highest = houses[i] maxAt[i] = highest for i in range(0, num-1): highest = maxAt[i+1] if houses[i] <= highest: print (hi...
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
//package TestOnly.Div2B_322.Code1; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); in...
JAVA
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
n=int(raw_input()) li=map(int, raw_input().split()) ans=[li[n-1]] temp=li[n-1] for i in xrange(n-2, -1, -1): if li[i]<=temp: ans.append(temp+1) else: ans.append(li[i]) temp=li[i] ans=ans[::-1] for i in xrange(len(ans)): print ans[i]-li[i],
PYTHON
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5; int n; bool flag; int a[MaxN + 5], b[MaxN + 5]; int Max = 1 >> 30; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = n; i >= 1; i--) { flag = 0; if (a[i] > Max) { Max = a[i]; flag = 1;...
CPP
581_B. Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> q(n); for (int i = 0; i < n; i++) { cin >> q[i]; } int mx = 0; vector<int> ans; for (int i = n - 1; i >= 0; i--) { ans.push_back(max(0, mx + 1 - q[i])); mx = max(mx, q[i]); } reverse(ans.begin(), ans....
CPP