Problem:


(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)

Beginner's Guide

Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.

Problem Statement

You will be given a contest schedule for D days.
For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.

Input

Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.

D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D

The constraints and generation methods for the input part are the same as those for Problem A.

For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.

Output

Let v_d be the satisfaction at the end of day d.
Print D integers v_d to Standard Output in the following format:

v_1
v_2
\vdots
v_D

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13

Sample Output 1

18398
35037
51140
65837
79325

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.

Next Step

We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\ldots,D, we select the contest type that maximizes the satisfaction at the end of day d. You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!

Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.
We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.
For more information, please refer to the editorial that will be published after the contest.



Sample input:
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13


Sample output:
18398
35037
51140
65837
79325

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int,input().split()))
s = []
day = [0 for i in range(26)]
for i in range(d):
    s.append(list(map(int,input().split())))
ans = 0
num = 1
for i in range(d):
    t = int(input())-1
    day[t] = num
    for j in range(26):
        if j == t:
            ans += s[i][j]
        else:
            ans -= c[j]*(num-day[j])
    print(ans)
    num += 1

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last = [0]*26
ans = 0
for d in range(D):
    max_s = int(input()) - 1
    last[max_s] = d+1
    ans += s[d][max_s]
    for i in range(26):
        ans -= (c[i]*(d+1 - last[i]))
    print(ans)

Submission status: Accepted

Solution code:
def data_input():
    D = int(input())
    C = tuple(map(int, input().split()))

    S = []
    for i in range(D):
        s = tuple(map(int, input().split()))
        S.append(s)

    return D, C, S


def score(D, C, S, T):
    """入力D, C, Sと出力Tからスコアを計算する関数"""

    last = [0] * 26  # 0で初期化されている

    def decrease(d, last):
        """d日めにiを開催した時の満足度の減少を返す関数"""
        res = 0
        for i in range(26):
            ith = C[i] * (d+1 - last[i])
            res -= ith
        return res

    V = []  # V[d]はd日めの満足度を表す
    for d, i in enumerate(T):
        if d == 0:
            v = 0
        last[i] = d + 1
        v += S[d][i] + decrease(d, last)
        V.append(v)
    return V

D, C, S = data_input()

T = []
for i in range(D):
    t = int(input()) - 1
    T.append(t)

V = score(D, C, S, T)

for v in V:
    print(v)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from decimal import Decimal
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

D = I()
C = LI()
s = [LI() for _ in range(D)]

T = [I() for _ in range(D)]
#print(D,C)
#print(s)
#print(T)
def last(d,i):
    T_d = T[:d]
    n = [j for j, x in enumerate(T_d,1) if x == i]
    if n:
        #print(T_d,i,"n=",n)
        return max(n)
    else:
        return 0
        
        
score = 0
for d in range(1,D+1):
    sum_c = 0
    for i in range(1,26+1):
        sum_c += C[i-1] * (d -last(d,i))
    score += s[d-1][T[d-1]-1] - sum_c
    print(score)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
import numpy as np

D = int(input())
c = np.array(input().split(), dtype=np.int32)
s = np.array([input().split() for _ in range(D)], dtype=np.int32)
t = [int(input()) for _ in range(D)]
last = np.zeros(26, dtype=np.int32)
# print(s)
# print(s.shape)

ans = []
point = 0
for i in range(D):
    last[t[i]-1] = i+1
    down = (i+1-last)*c
    point += s[i, t[i]-1] - down.sum()
    print(point)

Submission status: Accepted

Solution code:
D = int(input())
c = [int(x) for x in input().split()]
s = [input().split() for l in range(D)]
t = []
for i in range(D):
    t += [int(input())]
manzoku = 0
d = 1
last = [0]*26

for p in range(D):
    #タイプはt[p]-1,0~25 満足度増加 s[p][t[p]] p+1日目
    manzoku += int(s[p][t[p]-1])
    last[t[p]-1] = p+1
    for i in range(26):
        manzoku -= c[i] *(p+1-last[i])
    print(manzoku)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
def choice_contest(c, data_day, last, day, contest):
    contest -= 1
    #print(last)
    last = [i + 1 for i in last]
    # 今回開催するコンテストのlastを0にする
    last[contest] = 0
    #print(len(last))
    #print(last)
    # 不満度の計算
    d_satis = sum([last[i] * c[i] for i in range(26)])
    # i日目にcontestを選んだ場合の
    return [int(data_day[contest]) - d_satis, last]

def main():
    d = int(input())
    c = list(map(int,input().split()))
    data = [input().split() for _ in range(d)]
    last = [0] * 26
    ans = 0
    for i in range(d):
        s, last = choice_contest(c, data[i], last, i, contest = int(input()))
        ans += s
        print(ans)
    return 0

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# d日目の終わりの低下する満足度
def cost(c, d, lastdi):
    total = 0
    # print("{}日目".format(d))
    # print(lastdi)
    for i in range(26):
        total += c[i]*(d - lastdi[i])
    # print("cost:{}".format(total))
    return total

# 最終日
D = int(input())
# type毎の満足度の下がりやすさ
c = list(map(int, input().split()))
# [d,i]の満足度
s = [[] for _ in range(D)]
for d in range(D):
    si = list(map(int, input().split()))
    s[d] = si

# type毎の最後に開催された日を管理
lastdi = [0 for _ in range(26)]

ans = 0
for d in range(D):
    # d日目に選択されたtype
    typei = int(input()) - 1
    lastdi[typei] = d+1 # 日付なので+1
    ans += s[d][typei] - cost(c, d+1, lastdi)
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np

D=int(input())
c=[int(i) for i in input().split()]
s=[]
for d in range(D):
    s.append([int(i) for i in input().split()])

t=[]
for d in range(D):
    t.append(int(input()) - 1)

v = [0]*D
last = [[0 for i in range(26)] for d in range(D)]

for d in range(D):
    if d>=1:
        last[d] = last[d-1][:]
    last[d][t[d]] = d+1

for d in range(D):
    v[d] = s[d][t[d]] - sum([c[i]*(d+1 - last[d][i]) for i in range(26)])

v_sum=0
for d in range(D):
    v_sum+=v[d]
    print(v_sum)

Submission status: Accepted

Solution code:
D = int(input())
c_list = list(map(int,input().split(' ')))
s_list = []
for i in range(D):
    s_list.append(list(map(int,input().split(' '))))
t_list = []
for j in range(D):
    t_list.append(int(input()))
last_list = [0 for k in range(26)]
score = 0
point = 0
for day in range(D):
    point += s_list[day][t_list[day]-1]
    last_list[t_list[day]-1] = day+1
    for c in range(26):
        point -= c_list[c]*((day+1)-last_list[c])
    if(point>-1000000):
        score = point+1000000
    print(point)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D):
    s.append(list(map(int,input().split())))
t = []
for i in range(D):
    t.append(int(input()))

def last(d,la):
    s = 0
    for i in range(26):
        s += c[i] * (d - la[i])
    return s

lastday = [0]*26
a = 0
for d in range(D):
    lastday[t[d]-1] = d + 1
    a += s[d][t[d]-1]- last(d+1,lastday)
    print(a)

Submission status: Accepted

Solution code:
D=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(D):
  s.append(list(map(int,input().split())))
t=[]
for _ in range(D):
  t.append(int(input()))
g=0
for d in range(D):
  a=s[d][t[d]-1]
  b=0
  for i in range(26):
    for j in range(d+1,0,-1):
      if t[j-1]==i+1:
        b+=c[i]*(d+1-j)
        break
    else:
      b+=c[i]*(d+1)
  g+=a-b
  print(g)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
t = []
kankaku = [0 for i in range(27)]
last = [0 for i in range(27)]
man = 0
for i in range(D):
    s.append(list(map(int,input().rstrip().split(" "))))
for i in range(D):
    t.append(int(input())-1)
for i in range(D):
    man += s[i][t[i]]
    last[t[i]] = i + 1
    for i2 in range(26):
        man -= (i + 1 - last[i2]) * c[i2]
    print(man)

Submission status: Accepted

Solution code:
D=int(input())
c = [int(i) for i in input().split()]
s=[]
for i in range(D):
    s.append([int(j) for j in input().split()])
t=[0] * D
for i in range(D):
    t[i] = int(input())

tst = [0] * 26
last = [0] * 26
for i,j in enumerate(t):
    tst[j-1] += s[i][j-1]
    last[j-1] = i+1
    for k in range(26):
        if k != j-1:
            tst[k] -= (i+1 - last[k])*c[k] 
    print(sum(tst))

Submission status: Accepted

Solution code:
d = int(input())
ci = list(map(int, input().split()))
sdi_list = []
for i in range(d):
    sdi = list(map(int, input().split()))
    sdi_list.append(sdi)
td_list = []
for i in range(d):
    td = int(input())
    td_list.append(td)
lastdi = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
manzoku = 0
for i in range(d):
    manzokuteika = 0
    lastdi[td_list[i]-1] = i + 1
    for j in range(26):
        manzokuteika = manzokuteika + ci[j] * (i + 1 - lastdi[j])
    manzoku = manzoku + sdi_list[i][td_list[i]-1] - manzokuteika
    print(manzoku)

Submission status: Accepted

Solution code:
d =int(input())
c = list(map(int, input().split())) 
s = []
t = []

d_l = []
score = 0
soft = 0

for i in range(d):
    s.append(0)
    s[i] = list(map(int, input().split()))

for i in range(26):
    d_l.append(0)
    
for i in range(d):
    t = int(input())
    soft = 0
    
    for j in range(26):
        if t-1 == j:
            d_l[j] = 0
            score += s[i][j]
        else:
            d_l[j] += 1
            soft += c[j] * d_l[j]
    
    score -= soft
    print(score)

Submission status: Accepted

Solution code:
from operator import mul

D=int(input())
clist=list(map(int,input().split()))
slist=[]
for i in range (D):
    s=list(map(int,input().split()))
    slist.append(s)
tlist=[]
for i in range(D):
    t=int(input())
    tlist.append(t)

# print(clist,slist,tlist)
# D=5
# clist=[86, 90, 69, 51, 2, 96, 71, 47, 88, 34, 45, 46, 89, 34, 31, 38, 97, 84, 41, 80, 14, 4, 50, 83, 7, 82]

# slist=[[19771, 12979, 18912, 10432, 10544, 12928, 13403, 3047, 10527, 9740, 8100, 92, 2856, 14730, 1396, 15905, 6534, 4650, 11469, 3628, 8433, 2994, 10899, 16396, 18355, 11424], [6674, 17707, 13855, 16407, 12232, 2886, 11908, 1705, 5000, 1537, 10440, 10711, 4917, 10770, 17272, 15364, 19277, 18094, 3929, 3705, 7169, 6159, 18683, 15410, 9092, 4570], [6878, 4239, 19925, 1799, 375, 9563, 3445, 5658, 19857, 11401, 6997, 6498, 19933, 3848, 2426, 2146, 19745, 16880, 17773, 18359, 3921, 14172, 16730, 11157, 5439, 256], [8633, 15862, 15303, 10749, 18499, 7792, 10317, 5901, 9395, 11433, 3514, 3959, 5202, 19850, 19469, 9790, 5653, 784, 18500, 10552, 17975, 16615, 7852, 197, 8471, 7452], [19855, 17918, 7990, 10572, 4333, 438, 9140, 9104, 12622, 4985, 12319, 4028, 19922, 12132, 16259, 17476, 2976, 547, 19195, 19830, 16285, 4806, 4471, 9457, 2864, 2192]]
# tlist=[1, 17, 13, 14, 13]
noheldsday=[0]*26

benefit=0

for i in range (D):
    _noheldsday=list(map(lambda x: x+1,noheldsday))
    _noheldsday[tlist[i]-1]=0
    unpleasant=list(map(mul,clist,_noheldsday))
    
    v=slist[i][tlist[i]-1]-sum(unpleasant)
    benefit+=v
    noheldsday=_noheldsday
    
    print(benefit)

Submission status: Accepted

Solution code:
def complain(comp,c,k,last_hold,i):
    # print(k)
    if(k > 26):
        # print("___")
        return comp
    comp += c[k-1]*((i+1) - last_hold[k-1]) 
    k += 1
    # print(comp,"comp")
    return complain(comp,c,k,last_hold,i)

D = int(input())
c = list(map(int,input().split()))
s = ["_"]*(D)
# print(c)
for i in range(D):
    s[i] = list(map(int,input().split()))
last_hold = [0]*26
score = [0]*(D+1)

for i in range(D):
    score[i+1] += score[i]
    t = int(input())
    last_hold[t-1] = i+1
    comp = 0
    k = 1
    score[i+1] += s[i][t-1]    
    # print(s[i][t-1],"s")
    comp = complain(comp,c,k,last_hold,i)    
    score[i+1] -= comp
    # print(comp,"comp")
    # print(score[i+1],"score")

for i in range(D):
    print(score[i+1])

# Σ(Ci * (d - last(d,i)))
# (1~26)

# 18398
# 35037
# 51140
# 65837
# 79325

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
    s.append(list(map(int, input().split())))
t = []
for i in range(D):
    t.append(int(input()))

a = [0]*26
total = 0
for i in range(D):
    ts = t[i]

    a[ts-1] = i+1
    cs = sum([x * (i+1 - y) for x, y in zip(c, a)])

    total = total + s[i][ts-1] - cs
    print(total)

Submission status: Accepted

Solution code:
def f_last(d, i, lt):
  idx = []
  if i in lt[0:d]:
    idx = [j+1 for j, x in enumerate(lt[0:d]) if x == i]
  else:
    idx.append(0)
  return idx[-1]

d = int(input())
lc = list(map(int, input().split()))
ls = []
lt = []
for _ in range(d):
  ls.append(list(map(int, input().split())))

for _ in range(d):
  lt.append(int(input()))

v = 0
for dd in range(1, d+1):
  v_d = 0
  for i in range(len(lc)):
    v_d += lc[i]*(dd-f_last(dd, i+1, lt))
  v = v + ls[dd-1][lt[dd-1]-1] - v_d
  print(v)

Submission status: Accepted

Solution code:
D=int(input())
c=list(map(int,input().split()))
last=[0 for i in range(26)]
cost=[0 for i in range(26)]
degree=[0 for i in range(26)]
score=0
s=[]
t=[]
for _ in range(D):
  s.append(list(map(int,input().split())))
for _ in range(D):
  t.append(int(input()))
for d in range(D):
  for i in range(26):
    cost[i]+=c[i]*(d+1-last[i])
  k=t[d]-1
  cost[k]-=c[k]*(d+1-last[k])
  last[k]=d+1
  score+=s[d][k]
  print(score-sum(cost))

Submission status: Accepted

Solution code:
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 5
# 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
# 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
# 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
# 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
# 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
# 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
# 1
# 17
# 13
# 14
# 13
# """
# sys.stdin = io.StringIO(_INPUT)
# ####################################################################
D = int(input())
C = [int(i) for i in input().split()]

SS = [[int(i) for i in input().split()] for _ in range(D)]
T = [int(input()) for _ in range(D)]

L = [0]*26

v = 0
for d, t in enumerate(T):
  t -= 1
  L[t] = d+1

  v += SS[d][t]
  for c, l in zip(C, L):
    v -= c * (d+1 - l)
  # v += C[t]

  print(v)

Submission status: Accepted

Solution code:
D = int(input())

C = list(map(int, input().split()))

S = [list(map(int, input().split())) for i in range(D)]

L = [0 for i in range(26)]

T = [int(input()) for i in range(D)]

score=0

for d in range(D):
  score += S[d][T[d]-1]
  
  L[T[d]-1] = d+1
  down = 0
  for i in range(26):
    down+=C[i] * ((d+1) - L[i])

  score -=down
  
  print(score)

Submission status: Accepted

Solution code:
def main():
    d = int(input())

    c =list(map(int, input().split()))

    s = [[] for i in range(d)]
    for i in range(d):
        s[i] = list(map(int, input().split()))

    t = [0 for i in range(d)]
    for i in range(d):
        t[i] = int(input())

    ans = 0
    last = [0 for i in range(26)]

        
    for i in range(d):
        ans += s[i][t[i]-1]
        last[t[i]-1] = i+1

        sum_ = 0
        for j in range(26):
            sum_ += c[j] * (i+1-last[j])

        ans -= sum_
        print(ans)
        
main()

Submission status: Accepted

Solution code:
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(d)]
C=sum(c)
tot=0
mem=[0]*26
for i in range(d):
	t=int(input())
	mem[t-1]=i+1
	tot+=s[i][t-1]
	for j in range(26):
		tot-=c[j]*((i+1)-mem[j])
	print(tot)

Submission status: Accepted

Solution code:
D = int(input())
cs = list(map(int, input().split()))
ss = [input().split() for l in range(D)]
ts = [int(input()) for i in range(D)]
ans=0
all_cs=sum(cs)
cs_last=[0]*26

def c0(d):
    mainas=0
    for i in range(26):
        #print(cs[i]*(d-cs_last[i]))
        mainas-=cs[i]*(d-cs_last[i])
    return mainas



for i in range(D):
    cs_last[ts[i]-1]=i+1
    ans+=int(ss[i][ts[i]-1])+c0(i+1)
    
    print(ans)

Submission status: Accepted

Solution code:
def resolve():
    D = int(input())
    C = [int(x) for x in input().split()]
    S = []
    for i in range(D):
        S.append(list(map(int, input().split())))
    t = [int(input()) for _ in range(D)]
    last_d = []
    score = 0

    for d in range(D):
        score += S[d][t[d] - 1]
        last_d.append(t[d] - 1)
        for i in range(len(C)):
            if i in last_d:
                score -= C[i] * last_d[::-1].index(i)
            else:
                score -= C[i] * (d + 1)
        print(score)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = []
for d in range(D):
	s.append(list(map(int, input().split())))
last = [0 for i in range(26)]
v = 0
for d in range(1, D+1):
  i = int(input())
  last[i-1] = d
  v += s[d-1][i-1]
  for k in range(26):
    v -= c[k] * (d - last[k])
  print(v)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def down_pleasure(c_list, day_num, contest_last_day):
    """その日の満足度低下を返す"""
    sum_down_pl = 0
    for i in range(26):
        sum_down_pl += c_list[i] * (day_num - contest_last_day[i])

    return sum_down_pl


def calc_pleasure(s_list, t_list, d, c_list, contest_last_day):
    pleasure = 0

    for day, t_num in zip(range(d), t_list):
        pleasure += s_list[day][t_num-1]
        contest_last_day[t_num-1] = day + 1
        pleasure -= down_pleasure(c_list, day+1, contest_last_day)
        print(pleasure)

    return pleasure






def resolve():
    d = int(input().rstrip())
    c_list = list(map(int, input().split()))
    s_list = [list(map(int, input().split())) for i in range(d)]
    t_list = []

    for i in range(d):
        t_list.append(int(input().rstrip()))

    contest_last_day = []
    for i in range(26):
        contest_last_day.append(0)

    pleasure = calc_pleasure(s_list, t_list, d, c_list, contest_last_day)




if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
v = 0
last = [0 for _ in range(len(c))]

for day in range(D):
    v += s[day][t[day]-1] 
    last[t[day]-1] = day + 1
    for j in range(len(c)):
        v -= c[j]*(day + 1 - last[j])
    print(v)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

D = int(input())
c = list(map(int, input().split()))
s = []
t = []

for i in range(D):
    s.append(list(map(int, input().split())))

for i in range(D):
    t.append(int(input()) - 1)

last = [0] * 26

ans = 0

for i in range(D):
    ans = ans + s[i][t[i]]
    for j in range(26):
        if t[i] != j:
            last[j] += 1
            ans = ans - (c[j] * last[j])
        elif t[i] == j:
            last[j] = 0
    print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]
    t = [int(input()) for _ in range(d)]
    last = [0 for _ in range(26)]
    score = 0

    for di in range(1, d + 1):
        ti = t[di - 1]
        score += s[di - 1][ti - 1]

        last[ti - 1] = di

        for j, cj in enumerate(c, 1):
            score -= cj * (di - last[j - 1])

        print(score)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
d = int(sys.stdin.readline().rstrip())
list_c = list(map(int, sys.stdin.readline().rstrip().split()))
list_s = []
list_t = []
need = 0
for i in range(d):
  list_s.append(list(map(int, sys.stdin.readline().rstrip().split())))
for i in range(1, d+1):
  t = int(sys.stdin.readline().rstrip())
  list_t.append(t)
  need += list_s[i-1][t-1]
  MINUS = 0
  list_t1 = list_t[::-1]
  for j in range(1, 27):
    if not j in list_t1:
      MINUS += list_c[j-1] * len(list_t)
    else:
      MINUS += list_c[j-1] * list_t1.index(j)
  need -= MINUS
  print(need)

Submission status: Accepted

Solution code:
import numpy as np

d = int(input())
c = list(map(int, input().split()))
s = np.array([list(map(int, input().split())) for _ in range(d)])
t = [int(input()) for _ in range(d)]

last_day = np.zeros(26, dtype=int)

score = 0
for i in range(1, d + 1):
    last_day[t[i - 1] - 1] = i
    minus = ((last_day - i) * c).sum()
    score += s[i - 1, t[i - 1] - 1] + minus
    print(score)

Submission status: Accepted

Solution code:
D=int(input())
C=list(map(int, input().split()))
S=[list(map(int,input().split())) for i in range(D)]

T=[]
for i in range(D):
  T.append(int(input()))

def dissat(day):
  dissat = 0
  for i in range(26):
    if T[day-1]-1 == i:
      continue
    dissat += C[i]*(day-lastdays[i])

  return dissat    
    
def last(day):
  lastdays[T[day-1]-1] = day

sat = 0
lastdays = [0]*26

# main
for i in range(D):
  # dayi
  last(i)
  sat += S[i][T[i]-1] - dissat(i+1)
  print(sat)

Submission status: Accepted

Solution code:
import random
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]

A = [0]*26

ret = 0
for i in range(D):
    ret += s[i][t[i]-1]
    # print(ret)
    A[t[i]-1] = i+1
    for j in range(26):
        ret -= c[j] * (i+1 - A[j])
    print(ret)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    D = int(input().strip())
    C = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    S = np.empty((D, 26), dtype=np.int32)
    for i in range(D):
        s = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
        S[i, :] = s[:]
    T = np.array([int(input().strip()) for i in range(D)], dtype=np.int32)
    return D, C, S, T


@njit
def satisfaction(d, C, S, T, last):
    v = 0
    v += S[d, T[d]-1]
    last[T[d]-1] = d+1
    for i in range(26):
        v -= C[i] * ((d+1) - last[i])
    return v


@njit
def solve(D, C, S, T):
    last = np.zeros(26, dtype=np.int32)
    cumsat = 0
    for i in range(D):
        sat = satisfaction(i, C, S, T, last)
        cumsat += sat
        print(cumsat)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-28 21:02:34 +0900
# LastModified: 2020-06-28 22:01:44 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = []   # 満足度
    box = [-1]*26  # 各コンテストの実施日
    for i in range(d):
        s.append(list(map(int, input().split())))

    total_satisfy = 0
    for i in range(d):
        t = int(input())
        total_satisfy += s[i][t-1]
        box[t-1] = i
        for j in range(26):
            if box[j] == -1:
                total_satisfy -= c[j]*(i+1)
            else:
                total_satisfy -= c[j]*(i-box[j])
#        print(box)

        print(total_satisfy)






if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
D = int(input())
C = [*map(int, input().split())]
S = [[*map(int, input().split())] for _ in range(D)]
T = [int(input()) for _ in range(D)]

# print(D)
# print(C)
# print(*S,sep='\n')
# print(T)

O = [[0]*26 for _ in range(D)]
A = [[0]*26 for _ in range(D)]

def last(d,t):
    for i in range(d,-1,-1):
        if O[i][t] > 0: return i+1
    return 0

score = 0
t = 0
for d in range(D):
    t = T[d] - 1
    # print('t',t)
    O[d][t] = 1
    # print(O)
    dw = 0
    for i in range(26):
        # print('lday',last(d,i))
        dw += C[i]*((d+1) - last(d,i))
    A[d][t] = S[d][t] - dw
    score += A[d][t]
    # print(t+1,end=' ')
    # print(S[d][t],end=' ')
    # print(dw,end=' ')
    print(score)
    # t = (t+1) % 26

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]

def calc(D, s, t):
  last = [0 for _ in range(26)]
 
  value = 0
  for i in range(D):
    day = i + 1
    value += s[i][t[i]-1]
    last[t[i]-1] = day
    for j in range(26):
      value -= c[j] * (day - last[j])
    print(value)
calc(D, s, t)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

d = ni()
c = na()
s = nan(d)
t = nin(d)

last = [0] * 26

ans = 0
for i in range(d):
    sa = s[i]
    cur = t[i]
    cur -= 1
    ans += sa[cur]
    last[cur] = (i + 1)
    for j in range(26):
        ans -= c[j] * ((i + 1) - last[j])
    print(ans)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = [None] * D
for i in range(D):
    S[i] = list(map(int, input().split()))
T = [None] * D
for i in range(D):
    T[i] = int(input())

lasts = [0] * 26
score = 0
for d in range(D):
    t = T[d]-1
    score += S[d][t]
    d += 1
    lasts[t] = d
    score -= sum(C[i] * (d-l) for i, l in enumerate(lasts))
    print(score)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

d = ni()
c = na()
s = []

for i in range(d):
    ss = na()
    s.append(ss)

last = [0]*26
score = 0

for i in range(1,d+1): # i日目
    t = ni()
    t-=1 # 0-index
    last[t] = i
    score += s[i-1][t]
    for j in range(26):
        score -= c[j]*(i-last[j])
    print(score)


score = max(10**6+score, 0)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
t = [int(input()) for i in range(D)]
score = 0
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(len(t)):
    i = t[d] - 1
    last[i] = d+1
    score += s[d][i]
    score -= score_down(d+1)
    print(score)