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
import java.io.*; import java.util.*; public class CF581B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); int[] hh = new int...
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, i, temp; cin >> n; long long h[n], ans[n]; for (i = 0; i < n; i++) cin >> h[i]; temp = h[n - 1]; ans[n - 1] = 0; for (i = n - 2; i >= 0; i--) { if (h[i] > temp) { temp = h[i]; ans[i] = 0; } else { ans[i] = te...
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() STORE = [int(i) for i in raw_input().split()] ## COMPLEXITY REQUIRED Nlg(N) or less i = -1 arr = [] m = STORE[-1] while i > -1*len(STORE): if STORE[i] > m: m = STORE[i] arr.append(m) i -= 1 arr = list(reversed(arr)) result = [0] i = -2 while i >= -1*len(STORE) : if STORE[i] <= arr[i+1]: result...
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()) a = [int(x) for x in input().split()] m = [0 for x in range(n)] m[n - 1] = a[n - 1] for i in range(n - 2, -1, -1): m[i] = max(m[i + 1], a[i]) for i in range(n - 1): print(max(0, m[i + 1] + 1 - a[i]), end=" ") print(0)
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; const int N = 100001; int a[N]; int b[N]; int main(void) { int n; while (~scanf("%d", &n)) { int i, j; for (i = 1; i <= n; i++) scanf("%d", &a[i]); b[n] = 0; int MAX = a[n]; for (i = n - 1; i >= 1; i--) { if (a[i] <= MAX) b[i] = MAX + 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 m[100001], a[100001], n, t; cin >> n; for (int k = 1; k <= n; k++) cin >> a[k]; t = a[n]; for (int k = n - 1; k >= 1; k--) { if (a[k] <= t) m[k] = t - a[k] + 1; else { t = a[k]; m[k] = 0; } } m[n] = 0; 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.util.Scanner; public class abdelmagied { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int [] arr= new int[100000]; for(int i = 0 ; i < n ; i++) { arr[i] = sc.next...
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.*; public class Spoj { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int n=in.nextInt(); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=in.nextInt(); int right[]=ne...
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.*; import java.util.*; public class CodeforcesRound322 { static class ProblemB { static void Run() { IO.Initialization(); Solve(IO.reader, IO.writer); IO.Close(); } static void Solve(Scanner reader, PrintWriter writer) { int n = reader.nextInt(); int[] h = new ...
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
from collections import * def arr_inp(): return [int(x) for x in input().split()] def max_arr(a): d, ans, new = deque([a[-1]]), deque([0]), 0 for i in range(n - 2, -1, -1): if a[i] == d[0]: new = 1 elif a[i] > d[0]: new = 0 else: new = d[0] - ...
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 n, i, m, a[1000001], b[100001]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; m = a[n]; for (int i = n - 1; i >= 0; i--) { if (m >= a[i]) b[i] = m - a[i] + 1; else m = a[i]; } for (i = 1; 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
#include <bits/stdc++.h> using namespace std; int const N = 1e6 + 5; int n, m, arr[N], b[N], cnt = 0, ma; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } ma = -100; for (int i = n - 1; i >= 0; i--) { if (ma < arr[i]) { ma = arr[i]; continue; } else { 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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1], m = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } m = a[n - 1]; for (int i = n - 2; i >= 0; i--) { if (a[i] > m) { m = a[i]; a[i] = 0; } else if (a[i] < m) { a[i] = m + 1 - 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 sys import math n = int(input()) a = list(map(int, input().split())) mx = 0; ans = [ 0 for i in range(n)] for i in range(n-1, -1, -1): ans[i] = max(0, mx + 1 - a[i]) if a[i] > mx: mx = a[i]; for i in range(0,n): print(ans[i], 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
#include <bits/stdc++.h> using namespace std; long long a[100005], b[100005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; b[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; i--) b[i] = (b[i + 1]) > (a[i]) ? (b[i + 1]) : (a[i]); for (int i = 0; i < n; i++) { if (a[i] > 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
def make_luxurious (n,arr) : arr.reverse() tallest = arr[0] ans = [] ans.append(str(0)) for x in arr[1:] : if x > tallest : tallest = x ans.append(str(0)) else: ans.append(str((tallest-x)+1)) ans.reverse() return " ".join(ans) n = in...
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 copy n=int(input()) l=list(map(int,input().split())) m=copy.copy(l) ma=0 for i in range(n-2,-1,-1): if (l[i+1]>ma): ma=l[i+1] m[i]=ma for i in range(n-1): print(max(0,m[i]-l[i]+1),end=" ") print(0)
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()) L=list(map(int,input().split())) mayor=L[-1] L[-1]="0" for k in range(2,n+1): if(L[-k]>mayor): mayor=L[-k] L[-k]="0" else: L[-k]=str(mayor-L[-k]+1) print(" ".join(L))
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> #pragma warning(disable : 4996) const int N = 5e5 + 20; const long long int M = 1e17; using namespace std; int a[N]; void solve(int i, int m) { if (i < 0) return; solve(i - 1, max(a[i], m)); cout << max(0, m + 1 - a[i]) << ' '; } int main() { int n; cin >> n; for (int i = 0; i < 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
import java.util.Scanner; import java.util.TreeMap; import java.util.TreeSet; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Hash...
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
''' def max_left(k, a, i): maxiel = k for i in range(i, len(a)): if a[i] > maxiel: maxiel = a[i] if maxiel == k: return 0 return maxiel def find_max(a, start, stop): maxel = 0 ind = 0 for i in range(start, stop): if a[i] > maxel: maxel = a[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 = input() buildings = input().split(' ') m = 0 result = [] for i in range(len(buildings) - 1, -1, -1): b = int(buildings[i]) x = m - b if x < 0: result.append(0) m = b else: result.append(x + 1) print(' '.join(map(str, result[::-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; #pragma comment(linker, "/STACK:667177216") const long long mod = 1000000009; int main() { int n; cin >> n; vector<long long> ans(n, 0); vector<long long> mas(n, 0); for (int(i) = 0; (i) < n; i++) { cin >> mas[i]; } long long mx = mas[n - 1]; ans[n - 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.*; public class cp{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] a = new long[n]; long[] ans = new long[n]; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); } long max = a[n-1]; ans[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
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
n=int(raw_input()) N=map(int,raw_input().split()) N.reverse() a=[] ma=0 for i in range(n): a.append(max(0,ma-N[i]+1)) ma=max(N[i],ma) a.reverse() for i in a: 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
#include <bits/stdc++.h> using namespace std; int n, k, j, a[1000000], b[1000000]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> b[i]; k = b[n - 1]; for (int i = n - 2; i >= 0; i--) { if (k >= b[i]) a[i] = k - b[i] + 1; else k = b[i]; } for (int i = 0; i < n; i++) cout << 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; long long n, z, x = -1000000000, a[100001], b[100001]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i >= 1; i--) { b[i] = max(0LL, x - a[i] + 1); x = max(a[i], x); } for (int i = 1; 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
from collections import deque def ir(): return int(raw_input()) def ia(): line = raw_input() line = line.split() return map(int, line) # e + x = m + 1 # x = m + 1 - e n = ir() a = ia(); a.reverse() m = 0; ans = [] for e in a: ans.append(max(m + 1 - e, 0)) if e > m: m = e ans.reverse() ...
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; long long int num[200010]; priority_queue<pair<long long int, long long int> > q; vector<long long int> vt; int main() { long long int n, i, j, k, p, d, x, y, z, pre, f = 0; cin >> n; for (i = 1; i <= n; i++) { cin >> num[i]; q.push({num[i], i}); } pre = 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.*; import java.util.*; public class Solution implements Runnable { private void solve() throws IOException { //String s = nextToken(); int n = nextInt(); int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = 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
import java.util.*; import java.io.*; import java.util.stream.*; public class b { private void solve() throws IOException { int n = nextInt(); Integer[] a = new Integer[n]; for(int i = 0; i < n; ++i) { a[i] = nextInt(); } int curMax = 0; for(int i = 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
n=int(input()) h=list(map(int,input().split())) MaxH=0 H=[] for i in range(n-1,-1,-1): if h[i]>MaxH: H.append(0) MaxH=h[i] elif h[i]==MaxH: H.append(1) else: H.append(MaxH-h[i]+1) for i in range(n-1,-1,-1): print(H[i],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
x = input() a = map(int,raw_input().split()) ans = [0]*x best = a[-1] ii = x-1 while ii>0: ii-=1 if a[ii]>best: ans[ii] = 0 best = a[ii] else: ans[ii] = best-a[ii]+1 for ii in ans: print ii,
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()) arr=list(map(int,input().split())) h=0 for i in range(n-1,-1,-1): x=max(0,h-arr[i]+1) h=max(h,arr[i]) arr[i]=x print(*arr)
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
a = input() b = map(int,raw_input().split()) rm = 0 out =[] for i in reversed(range(a)): if b[i] <= rm: out.append(rm+1-b[i]) elif b[i] > rm: out.append(0) rm = b[i] else: out.append(0) out.reverse() print(' '.join(str(x) for x in out))
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()) x = list(map(int, input().split())) x = [0]+x y = [0]*(n+1) mx = 0 for i in range(n,0,-1): y[i] = max(0,mx-x[i]+1) mx = max(mx,x[i]) for i in range(1,n+1): print(y[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
#include <bits/stdc++.h> using namespace std; int n, i, j, t[100010], maxx[100010]; inline int max(int a, int b) { if (a > b) return a; else return b; } map<int, int> mp; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &t[i]), mp[t[i]] = i; for (i = n; i >= 1; i--) maxx[i] = max(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
import static java.lang.System.in; import java.io.IOException; public class B { public static void main(String[] args) throws IOException { InputReader in = new InputReader(); int n = in.readInt(); int[] arr = new int[n]; for(int i =0;i<n;i++) { arr[i]=in.readInt(); } int maxi[] = new int[n+1]; f...
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; int a[111111], b[111111]; cin >> n; for (int i = 0; i < n; i++) scanf("%d", &a[i]); int mx = -1; for (int i = n - 1; i >= 0; i--) { if (a[i] > mx) { mx = a[i]; b[i] = 0; } else { b[i] = mx - a[i] + 1; } } for...
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=a[-1] l=[0]*n for i in range(n-2,-1,-1): x=max(0,m-a[i]+1) l[i]=x m=max(a[i],m) print(*l)
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()) l=list(map(int,input().split()))[::-1] m=0 l2=[] for i in range(n): if l[i]>m: l2.append(0) m=l[i] elif l[i]==m: l2.append(1) else: l2.append(m-l[i]+1) print(*l2[::-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.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.lang.*; import java.util.ArrayList; import java.math.BigInteger; public class me { public static void main(String[] args) { // TODO Auto-generated method stub Scanner br = new Scanner(System.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
#include <bits/stdc++.h> using namespace std; const int MX = (int)1e6 + 17; const int MOD = (int)1e9 + 7; const long long oo = (long long)1e18 + 7; const int INF = (int)999999999; const int N = (int)1e5 + 17; const int di[4] = {-1, 0, 1, 0}; const int dj[4] = {0, 1, 0, -1}; inline long long IN() { long long x = 0, ch...
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 m = 0, i, n, k, a[100000], b[100000]; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = n - 1; i >= 0; i--) { if (m < a[i]) { m = a[i]; b[i] = 0; } else b[i] = m - a[i] + 1; } 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
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int t = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] > t) { t = a[i]; b[i] = 0; } else b[i] = t - a[i] + 1; } for (int 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
/** * Prerequisite: * Algorithm: */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.InputMismatchException; public class _581B_LuxuriousHouses{ static class ProblemSolver{ public void solveTheProblem(InputReader in,PrintWriter out...
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]; int b[100100]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; b[n] = 0; int Max = a[n]; for (int i = n - 1; i >= 1; i--) { if (Max < a[i]) { Max = a[i]; b[i] = 0; } else { b[i] = Max + 1 - 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(input()) hs = list(map(int, input().split())) r = [] maxi = 0 for h in hs[::-1]: r.append(max(0, maxi - h + 1)) maxi = max(maxi, h) print(' '.join(map(str, r[::-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
n = int(raw_input()) a = map(int, raw_input().split(' ')) mi = n - 1 m = a[mi] res = [] for i in reversed(xrange(n)): if m < a[i]: m = a[i] res.append(0) elif m == a[i] and i != n - 1: res.append(1) elif m == a[i]: res.append(0) elif m > a[i]: res.append(m - a[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.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
n = int(input()) lst = list(map(int, input().split())) mx = 0 arr = [0] * n for i in reversed(range(n)): if lst[i] <= mx: arr[i] = mx - lst[i] + 1 mx = max(mx, lst[i]) for i in arr: print(i, 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 sys input = lambda:sys.stdin.readline() int_arr = lambda: list(map(int,input().split())) str_arr = lambda: list(map(str,input().split())) get_str = lambda: map(str,input().split()) get_int = lambda: map(int,input().split()) get_flo = lambda: map(float,input().split()) mod = 1000000007 def solve(n,arr): out =...
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.*; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] h = new long[n]; long[] d = new long[n]; for (int i = 0; i < n; i++) { h[i] = sc.nextLong(); } ...
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; vector<int> v; int main() { int n, i, mn = 0; cin >> n; int a[n + 5], b[n + 5]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = n - 1; i >= 0; i--) { if (a[i] > mn) { v.push_back(0); } else { v.push_back(mn + 1 - a[i]); } mn = m...
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.*; import java.util.*; import java.math.*; public class Main2 { public static void main(String[] args) throws IOException { File file = new File("in"); BufferedReader in; if (file.exists()) { in = new BufferedReader(new FileReader(file)); } else { in = new BufferedReader(new InputStreamReader(Sys...
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
import java.io.*; import java.util.*; import java.lang.*; public class Rextester{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = new Integer(br.readLine()); StringTokenizer st = new StringTokenizer(...
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.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Stack; public final class Main {...
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() m = 0 a = list() for x in reversed(map(int, raw_input().split())): a.append(max(m - x + 1, 0)) m = max(m, x) print ' '.join(map(str, reversed(a)))
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 com.codeforces.algoshots.rating1100.luxurious.houses; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { FastScanner fs = new FastScanner(); int n = f...
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()) l=[int(i) for i in input().split()] ans=[0] mx=l[n-1] #print(0,end=' ') for i in range(n-2,-1,-1): if l[i]>mx: ans.append(0) else: ans.append(mx-l[i]+1) mx=max(mx,l[i]) ans=ans[::-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; int arr[100001]; int v[100001]; for (int i = 0; i < n; i++) cin >> arr[i]; int mx = arr[n - 1]; v[0] = 0; int c = 1; for (int i = n - 2; i >= 0; i--) { if (mx >= arr[i]) { v[c] = mx - arr[i] + 1; c++; } els...
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; long long a, b, c, arr[100005]; long long ma[100005]; int main() { cin >> a; for (int i = 1; i <= a; i++) { cin >> arr[i]; } for (int i = a; i >= 1; i--) { ma[i] = max(ma[i + 1], arr[i]); } for (int i = 1; i <= a; i++) { if (ma[i + 1] < arr[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, h[100001], ans[100001]; cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; ans[n - 1] = 0; int m = h[n - 1]; for (int i = n - 2; i >= 0; i--) { if (h[i] > m) { m = h[i]; ans[i] = 0; } else { ans[i] = m - h[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.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; /** * Built using CHelper plug-in * Actual soluti...
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; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; vector<pair<long long, int> > t; for (int i = 0; i < n; i++) { t.push_back(make_pair(a[i], i)); } sort(t.begin(), t.end(), greater<pair<long long, int> >()); vector<...
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.ArrayList; import java.util.Scanner; public class m4 { public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=s.nextInt(); int b[]=new int[n]; b[n-1]=0; int max=a[n-1]; for(int i=n-2;i>=0;i--) { if(a[i]<=m...
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.*; import java.util.*; public class C322B { public static StringTokenizer st; public static void nextLine(BufferedReader br) throws IOException { st = new StringTokenizer(br.readLine()); } public static String next() { return st.nextToken(); } 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class Main { static final int mod = (int)1e9+7; public static void main(String[] args) throws Excep...
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 NBMAX = 1000 * 100 + 1; int main() { int n; cin >> n; vector<pair<int, int> > v; v.resize(n); for (int x = 0; x < n; x++) { cin >> v[x].first; } int m = 0; for (int i = (int)v.size() - 1; i >= 0; i--) { v[i].second = m; m = max(m, v[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.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.InputMismatchException; public class Main { class MyScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; BufferedInputS...
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.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.StringTokenizer; /** * Created by yujiahao on 3/31/16. */ public class cf_322_b { private FastScanner in; private PrintWriter out; public...
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, m; cin >> n; std::vector<int> v(n), s; for (int i = 0; i < n; ++i) cin >> v[i]; reverse(v.begin(), v.end()); m = v[0]; for (int i = 0; i < n; ++i) { if (v[i] > m || i == 0) { s.push_back(0); m = v[i]; } else s.push...
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 Code581B { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] houses = new int[n]; for(int i = 0; i < n; i++) houses[i] = scanner.nextInt(); int max = 0; for(int i = n - 1; 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
import sys #sys.stdin = open('input.txt') #sys.stdout = open('output.txt', 'w') n = int(input()) h = [int(i) for i in input().split()] h = h[::-1] ans = [] curmax = h[0] - 1 for i in range(n): if h[i] <= curmax: ans.append(curmax + 1 - h[i]) else: ans.append(0) curmax = max(curmax, h[i]) ans = ans[::-1] for ...
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
//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(); ...
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
a=int(input()) x=list(map(int,input().split())) y=[0] mx=x[-1] for i in range(a-2,-1,-1): y.append(max(0,mx-x[i]+1)) mx=max(mx,x[i]) print(' '.join(map(str,y[::-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
n = input() a = map(int, raw_input().split()) h = 0 ans = [] for _ in a[::-1]: ans += [max(h+1-_, 0)] h = max(h, _) print ' '.join(map(str, ans[::-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; int main() { int n = 0; cin >> n; int *heights = new int[n]; int *answers = new int[n]; for (int i = 0; i < n; ++i) { cin >> heights[i]; } int max = 0; for (int i = n - 1; i >= 0; --i) { int diff = max - heights[i] + 1; if (diff < 0) diff = 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.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class R322B { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWr...
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.*; public class Test { public static Scanner scn = new Scanner(System.in); public static void main(String[] args) { int n=scn.nextInt(); int[] hrr=new int[n]; for(int i=0;i<n;i++){ hrr[i]=scn.nextInt(); } int[] arr=new int[n]; int max=hrr[n-1]; for(int i=n-2;i>=0;i--){ if(hrr...
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 Scan() { int res = 0, ch, flag = 0; if ((ch = getchar()) == '-') flag = 1; else if (ch >= '0' && ch <= '9') res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0'; return flag ? -res : res; } void Out(int a) { if (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
n = int(input()) h = list(map(int, input().split())) m = h[-1] res = [] for x in h[::-1]: res.append(str(max(0, m-x))) m = max(m, x+1) print (' '.join(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
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Luxi{ static class Fa...
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.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.management.MemoryType; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import java.util.function.Function; public clas...
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 = list(map(int, input().split())) worst = 0 for i in reversed(range(n)): b = a[i] if a[i] <= worst: a[i] = worst - a[i] + 1 else: a[i] = 0 if b > worst: worst = b print(' '.join(map(str, 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; const int maxn = 1e5 + 100; int a[maxn], b[maxn]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int height = 0; for (int i = n; i > 0; i--) { if (a[i] > height) b[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> int f[100100]; int main() { FILE *fin; fin = stdin; int n, mx, t; fscanf(fin, "%d", &n); for (int i = 0; i < n; i++) { fscanf(fin, "%d", &f[i]); } mx = 0; for (int i = n - 1; i >= 0; i--) { t = f[i]; if (f[i] > mx) { f[i] = 0; mx = t; } else { f...
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
#-*- coding: utf-8 -*- n = int(input()) houses = list(map(int, input().split())) height = [0] result = [] for i in range(n): if houses[n - i - 1] > height[i]: height.append(houses[n - i - 1]) result.append(0) else: height.append(height[i]) result.append(height[i] - houses[n - i - 1] + 1) for i in range(n):...
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.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); ArrayList<Integer> res = new ArrayList<>(); for(int ...
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.*; import java.util.StringJoiner; import java.util.StringTokenizer; public class _581B { public static void main(String[] args) throws Exception { Reader.init(System.in); BufferedWriter cout = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Reader.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
import java.util.Scanner; public class Div2_581_B { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] t = new int[n]; int[] result = new int[n]; while (n > 0) { t[t.length - n] = scan.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
n = int(input()) h = list(map(int,input().split())) maxh = 0 a = [0] * n for i in range(n-1,-1,-1): if h[i]>maxh: maxh = h[i] a[i] = 0 elif h[i]<=maxh: a[i] = max(0,maxh+1-h[i]) print(' '.join(map(str,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
'''input 4 3 2 1 4 ''' n = int(input()) a = list(map(int, input().split())) m, l = 0, [] for _ in range(n): x = a.pop() if x > m: m = x l.append(0) else: l.append(m - x + 1) print(" ".join(map(str, l[::-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 main() { int n, x[100000], res[100000]; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i]; res[i] = 0; } int ma = x[n - 1]; for (int i = n - 2; i >= 0; i--) if (x[i] > ma) ma = x[i]; else res[i] = ma - x[i] + 1; for (int 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
import java.util.Scanner; /** * Created by MenonS on 02-10-2015. */ public class B322 { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int h = scanner.nextInt(); int[] floors = new int[h]; int[] output = new int[h]; for(int i=0;i<h;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()) height = list(map(int, input().split())) maxHeight = [0] * n # position i holds the tallest building in positions [i+1,n) m = 0 for i in range(n-1,0,-1): m = max(height[i], m) maxHeight[i-1] = m ans = [max(m - h + 1, 0) for (h,m) in zip(height, maxHeight)] print(' '.join([str(x) for x in 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
n = int(raw_input()) h = raw_input().strip().split() for i in range(n): h[i] = int(h[i]) m = 0 add = [] for i in range(n-1, -1, -1): if h[i] <= m: add.append(m - h[i] + 1) else: add.append(0) m = max(m, h[i]) for i in range(n): print add[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
import java.util.*; public class Car { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; int[] dh = new int[n]; for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); dh[n-1] = 0; String ans = "0"; for (int j = n - 2; j >= 0; j-...
JAVA