You are viewing a single comment's thread. Return to all comments →
import math import os import random import re import sys
#
# def billboards(n,k, revenue): N,K=n,k total = sum(revenue)
if K == N: return (total) else: x = revenue[: K + 1] min_value = min(x) min_index = x.index(min_value) for i in range(K + 1, N): if i - min_index >= K: min_value = min(x[i - (K + 1) : i + 1]) min_index = x.index(min_value) x.append(min_value + revenue[i]) if x[i] < min_value: min_value = x[i] min_index = i return (total - min(x[N - (K + 1) :]))
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) k = int(first_multiple_input[1]) revenue = [] for _ in range(n): revenue_item = int(input().strip()) revenue.append(revenue_item) result = billboards(n,k, revenue) fptr.write(str(result) + '\n') fptr.close()
Seems like cookies are disabled on this browser, please enable them to open this website
Billboards
You are viewing a single comment's thread. Return to all comments →
!/bin/python3
import math import os import random import re import sys
#
Complete the 'billboards' function below.
#
The function is expected to return an INTEGER.
The function accepts following parameters:
1. INTEGER k
2. INTEGER_ARRAY revenue
# def billboards(n,k, revenue): N,K=n,k total = sum(revenue)
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')