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:
import numpy as np
last=[0]*26
D=int(input())
c=list(map(int, (input().split(' '))))
s=[]
a=[0]*D

sat=0

for i in range(D):
    s.append(list(map(int, (input().split(' ')))))
for i in range(D):
    a[i]=int(input())
    last[a[i]-1] = i+1
    sat += s[i][a[i]-1] - np.dot(c, list(map(lambda x: i+1-x, last)))
    print(sat)

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()))

# last(d, i)を計算するためのメモ
dp = [0] * 26


def dec(d):
    # d日の終わりに起こる満足度の減少計算の関数
    s = 0
    for j in range(26):
        s += c[j] * (d - dp[j])

    return s


# vは満足度
v = 0
for i in range(D):
    # 初日の満足度
    if (i == 0):
        v += s[i][t[i] - 1]
        # 開催されたコンテストの日付をメモ
        dp[t[i] - 1] = (i + 1)
        v -= dec(i + 1)
        print(v)
        continue

    # elif (0 < i and i < D - 1):
    v += s[i][t[i] - 1]
    dp[t[i] - 1] = (i + 1)
    v -= dec(i + 1)
    print(v)

Submission status: Accepted

Solution code:
d=int(input())
a=[0 for i in range(26)]
c=list(map(int,input().split()))
l=[]
for i in range(d):
    l.append(list(map(int,input().split())))
    #print(c.index(max(c))+1)
p=[0]
for i in range(1,d+1):
    t=int(input())-1
    a[t]=i
    k=0
    for j in range(26):
        k+=c[j]*(i-a[j])
    p.append(p[i-1]+l[i-1][t]-k)
print(*p[1:],sep='\n')

Submission status: Accepted

Solution code:
#!/usr/bin/env python

def main():
    d = int(input())
    c_lst = list(map(int, input().split()))
    s_mat = [list(map(int, input().split())) for _ in range(d)]

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

    scr = 0
    last = [-1 for _ in range(26)]
    for day in range(d):
        t = t_lst[day]
        scr += s_mat[day][t]
        last[t] = day
        for typ in range(26):
            scr -= c_lst[typ] * (day - last[typ])
        print(scr)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
'''
Introduction to Heuristics Contest
A - AtCoder Contest Scheduling
'''

def main():
    # 本番テストケースは365
    D = int(input())

    # コンテストタイプごとの満足度の下がりやすさ
    C = list(map(int, input().split()))

    # 満足度row日目にコンテストcolタイプを開催したときの満足度の増加
    S = []
    for _ in range(D):
        sday = list(map(int, input().split()))
        S.append(sday)

    ''' とりあえず順番にやってくだけ
    for i in range(D):
        tmp = i % 26 + 1
        print(tmp)
    '''

    ''' 満足度Siの最高を選ぶ、満足度低下するCは未考慮
    for i in range(D):
        high = S[i].index(max(S[i])) + 1
        print(high)
    '''

#main()

def intro_heuristics_b():
    # 本番テストケースは365
    D = int(input())

    # コンテストタイプごとの満足度の下がりやすさ
    C = list(map(int, input().split()))

    # 満足度row日目にコンテストcolタイプを開催したときの満足度の増加
    S = []
    for _ in range(D):
        sday = list(map(int, input().split()))
        S.append(sday)

    # 回答(出力)
    T = [int(input()) for _ in range(D)]

    # さいごに開催したコンテストの日付
    last = [-1] * 26

    # 満足度と不満度を計算して出力
    val = 0
    for d in range(D):
        idx = T[d] - 1
        satis = S[d][idx]
        last[idx] = d
        complain = 0
        for j in range(26):
            complain += C[j] * (d - last[j])
        val += satis - complain
        print(val)

intro_heuristics_b()

#def intro_heuristics_c():

Submission status: Accepted

Solution code:
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(D)]
ld=[0]*26
ans=0
for i in range(D):
    v=int(input())-1
    ans+=s[i][v]
    ld[v]=i+1
    for j in range(26):
        ans-=(i+1-ld[j])*c[j]
    print(ans)

Submission status: Accepted

Solution code:
import bisect

def last(d,i):
    x = bisect.bisect_right(last_hol[i],d,)
    #print(x,last_hol[i])
    if x == 0:
        return 0
    else:
        return last_hol[i][x-1]

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
last_hol = {i:[] for i in range(1,27)}
t = []
for i in range(d):
    ti = int(input())
    last_hol[ti].append(i+1)
    t.append(ti)
ans = 0
a = [0]*d
for i in range(d):
    ti = t[i]
    ans += s[i][ti-1]
    for j in range(1,27):
        ans -= c[j-1]*(i+1-last(i+1,j))
    print(ans)

Submission status: Accepted

Solution code:
import random

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(random.uniform(0,26)))
    t.append(int(input()))
lastds = [0]*26
ans = 0
satisfaction = 0
#initial
for d in range(D):
    lastds[t[d]-1] = d+1
    satisfaction += S[d][t[d]-1]
    for i in range(26):
        satisfaction -= C[i] * (d+1-lastds[i])
    print(satisfaction)

Submission status: Accepted

Solution code:
day_count = int(input())
decline = list(map(int,input().split()))
score_list = []
schedule = [0] * 26
for i in range(day_count):
    score_list.append(list(map(int,input().split())))

result = 0


for i in range(day_count):
    temp = int(input()) - 1
    
    result += score_list[i][temp]
    
    for j in range(len(schedule)):
        if j != temp:
            schedule[j] += 1
            result -= schedule[j] * decline[j] 
        else:
            schedule[j] = 0
    
    print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from collections import defaultdict

def score(D, c, s, v):

    ret = []
    last = defaultdict(int)

    satisfaction = 0
    for d in range(1, D+1):
        satisfaction += s[(d, v[d])]
        last[v[d]] = d
        for i in range(1,27):
            satisfaction -= c[i]*(d - last[i])
        ret += [satisfaction]

    return '\n'.join(map(str, ret))

D = int(input())
c = input().split(' ')
c = list(map(int, c))
c = [float("inf")] + c
s = dict()
v = [float("inf")]
for i in range(D):
    row = input().split(' ')
    for j, e in enumerate(row):
        e = int(e)
        s[(i+1, j+1)] = e
for _ in range(D):
    v += [int(input())]

print(score(D, c, s, 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)]

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

last = [0]*26
S = 0
for d in range(1, D+1):
    # last更新
    for j in range(26):
        if j == t[d-1]-1:
            last[j] = d

    # plus部分
    S += s[d-1][t[d-1]-1]

    # minus部分
    m = 0
    for j in range(26):
        m += c[j] * (d-last[j])
    
    S -= m
    
    print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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)]
    
    ptn = len(c)
    last = [0]*ptn
    res = 0

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

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

        res += s[i][sel] - mns
        print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

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

ans = 0
minus = 0
last = [0]*26
for i in range(D):
    ans += S[i][t[i]-1]
    minus = 0
    last[t[i]-1] = i+1
    for j in range(26):
        minus += C[j]*(i-last[j]+1)
    ans -= minus
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np

D = int(input())
c = np.array( list(map(int, input().split())) )
s = [[] for i in range(365+1)]
for i in range(D):
  s[i] = list(map(int, input().split()))
#
last = np.array( [-1]*26 )

v = 0
for d in range(D):
  t =  int(input())
  t -= 1
  last[t] = d
  v += s[d][t]
  v -= sum( (d-last)*c )
  print(v)
#

Submission status: Accepted

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

t = [0]*D
v = [0]*D
d = [0]*26

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

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

now = 0

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

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = []
for day in range(D):
  S.append(list(map(int, input().split())))
T = []
for day in range(D):
  T.append(int(input()) - 1)
lasts = [-1] * 26
ans = 0
# simulate every day.
for day in range(D):
  ans += S[day][T[day]]
  lasts[T[day]] = day
  # verification for each contests.
  for i in range(26):
      ans -= C[i] * (day - lasts[i])
  print(ans)

Submission status: Accepted

Solution code:
def dissatisfy(c, last, d, v):
    ans = 0
    for i in range(0, 26):
        if (i != v - 1):
            ans += c[i] * (d - last[i])
    return ans


def main():
    D = int(input())
    c = list(map(int, input().split()))
    last = [0] * 27
    s = list()
    ans = 0

    for d in range(0, D):
        s.append(list(map(int, input().split())))
    for d in range(1, D + 1):
        v = int(input())
        ans += s[d-1][v-1]
        ans -= dissatisfy(c, last, d, v)
        for j in range(0, 27):
            if j == v - 1:
                last[j] = d
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, heapq

def calcScores(D, complaints, satisfications, HoldedContestDays):
    TotalSatisfications = [0]
    ContestDays = [1] * 26
    complaint_all = 0
    for i in range(26):
        complaint_all += complaints[i]

    complaint_sum = 0
    for i in range(D):
        complaint_sum += complaint_all
        Contest = HoldedContestDays[i]
        complaint_sum -= ContestDays[Contest] * complaints[Contest]
        ContestDays[Contest] = 0

        satisfication_day_i = TotalSatisfications[-1] + satisfications[i][Contest] - complaint_sum
        TotalSatisfications.append(satisfication_day_i)
        for j in range(26):
            ContestDays[j] += 1
    return TotalSatisfications

def calccontestnumbers(D, complaints, satisfications):
    ContestDays = [1] * 26
    HoldedContests = [-1] * D
    for i in range(D):
        Demands = []
        for j in range(26):
            Demand_j = ContestDays[j] * complaints[j] + satisfications[i][j]
            heapq.heappush(Demands, (-Demand_j, j) )
            ContestDays[j] += 1
        print("Day", i, ":", Demands)
        Demand_Contest = heapq.heappop(Demands)
        Contest = Demand_Contest[1]
        ContestDays[Contest] =1
        HoldedContests[i] = Contest+1
    return HoldedContests



"""
13: 19922, 89
20: 19830, 80

20: 19830 - 80 * 5 = 19430
13: 19922 - 89 * 2 = 19744
毎日1つのコンテスト
満足度をあげるようにコンテスト
ci * (最後にコンテストを行ってからの経過日数)満足度低下
上昇値はs_d_i

"""
if(__name__ == "__main__"):
    D = int(input().strip())
    complaints = list(map(int, input().split() ) )

    satisfications = []
    for i in range(D):
        satisfication = list(map(int, input().split() ) )
        satisfications.append(satisfication)
    HoldedContestDays =[0] * D
    for i in range(D):
        HoldedContestDays[i] = int(input().strip())
        HoldedContestDays[i] -= 1
    Scores = calcScores(D, complaints, satisfications, HoldedContestDays)
    for i in range(D):
        print(Scores[i+1])

Submission status: Accepted

Solution code:
d = int(input())

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

s = []

for _ in range(d):
    temp = list(map(int,input().split()))

    s.append(temp)

choices = []

for _ in range(d):
    temp = int(input())

    choices.append(temp)

def calc_point(point_list, interval, choice):
    point = 0

    for i, day in enumerate(interval):
        point -= c[i] * day

    point += point_list[choice - 1]

    return point

interval = [0] * 26

result = 0

for i in range(d):
    choice = choices[i]

    interval = [x + 1 for x in interval]

    interval[choice - 1] = 0

    result += calc_point(s[i], interval, choice)

    print(result)

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

d = inn()
c = inl()
s = []
for i in range(d):
    s.append(inl())
t = []
for i in range(d):
    t.append(inn()-1)
last = [-1]*26
sm = 0
for i in range(d):
    tt = t[i]
    sm += s[i][tt]
    last[tt] = i
    for j in range(26):
        sm -= c[j]*(i-last[j])
    print(sm)

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)]

points=0
day_last=[0]*26

def minus(day):
    return sum([c[i]*(day+1-day_last[i]) for i in range(26)])

def plus(day,contest_number):
    return s[day][contest_number-1]

for day,contest_number in enumerate(t):
    day_last[contest_number-1]=day+1
    points=points+plus(day,contest_number)-minus(day)
    print(points)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [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]
#1日目
for day in range(D):
  yasumi = list(map(lambda x: x + 1, yasumi))
  yasumi[T[day] - 1] = 0
  manzoku += S[day][T[day] - 1]
  for i in range(26):
    manzoku -= C[i] * yasumi[i]
  print(manzoku)

Submission status: Accepted

Solution code:
import numpy as np

D = int(input())
C = np.array(list(map(int, input().split())))
S = []
for i in range(D):
    s = list(map(int, input().split()))
    S.append(s)
S = np.array(S)
T = [int(input()) for _ in range(D)]

last = np.zeros(26, dtype=np.int64)


def decrease(d, last):
    res = np.sum(C * (d - last))
    # print(d, res, C * (d - last))
    return res


manzoku = 0
# kaisai = dict()

# print(S, T, C)
for day, t in enumerate(T):
    t -= 1
    manzoku += S[day, t]  # d 日目にタイプi のコンテストを開催した場合、満足度が S[d,i]増加することが予め分かっています。
    last[t] = day + 1
    manzoku -= decrease(day + 1, last)

    print(manzoku)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [[] for _ in range(D)]
t = []
for i in range(D):
    s[i] = list(map(int, input().split()))
for i in range(D):
    t.append(int(input()))
stf = [0] * 26
ld = [0] * 26
d = 0

def lower():
    lw = 0
    for i in range(26):
        lw += c[i] * (d - ld[i])
    return lw

x = 0
for i in range(D):
    d += 1
    x += s[i][t[i]-1]
    ld[t[i]-1] = d
    x -= lower()
    print(x)

Submission status: Accepted

Solution code:
d=int(input())
c=list(map(int,input().split()))
sa=[list(map(int,input().split())) for _ in range(d)]
last=[-1]*26
ty=[int(input())-1 for _ in range(d)]
sat=0
for day,i in enumerate(ty):
  last[i]=day
  sat+=sa[day][i]
  for j in range(26):
    sat-=c[j]*(day-last[j])
  print(sat)
  

"""
18398
35037
51140
65837
79325
"""

Submission status: Accepted

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

for i in range(D):
  tmp=list(map(int,input().split()))
  s.append(tmp)
for i in range(D):
  tmp=int(input())-1
  t.append(int(tmp))

for i in range(1,D+1):
  v+=s[i-1][t[i-1]]
  lastday[t[i-1]]=i
  for j in range(26):
    v-=c[j]*(i-lastday[j])
  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)]
T = [int(input()) for i in range(D)]
SUM = 0
last = [0] * 28
for d in range(1, D + 1):
    i = T[d - 1]
    SUM += S[d - 1][i - 1]
    SU = 0
    last[i] = d
    for j in range(1, 27):
        SU += (c[j - 1] * (d - last[j]))
    SUM -= SU
    print(SUM)

Submission status: Accepted

Solution code:
import sys
import numpy as np
from operator import mul
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

d = int(readline())
c = list(map(int, readline().split()))
s = []
for _ in range(d):
    add = list(map(int, readline().split()))
    s.append(add)

#t = [0] * d
day = 0
satisfy = 0
sumC = sum(c)
count = np.zeros(26)

for i in range(d):
    t = int(readline()) - 1
    up = s[day][t]
    count += 1
    count[t] = 0
    sub = map(mul, count, c)
    satisfy += (up - sum(sub))
    # satisfy
    print(int(satisfy))
    day += 1

Submission status: Accepted

Solution code:
import numpy as np

d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) - 1 for _ in range(d)]
last = np.zeros(26, dtype="i8")

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

Submission status: Accepted

Solution code:
import numpy as np
import numba


@numba.jit('i8[:](i8, i8[:], i8[:, :], i8[:])')
def solve(dd, c_arr, s_arr, t_arr):
    last_d = np.zeros(26, dtype=np.int64) - 1
    score = 0
    score_arr = np.zeros(dd, dtype=np.int64)
    for d in range(dd):
        score += s_arr[d, t_arr[d] - 1]
        last_d[t_arr[d] - 1] = d
        score -= (c_arr * (d - last_d)).sum()
        score_arr[d] = score
    return score_arr


def main():
    d = np.int64(input())
    c_arr = np.array(list(map(int, input().split()))).astype(np.int64)
    s_arr = np.array([list(map(int, input().split())) for _ in range(d)]).astype(np.int64)
    t_arr = np.array([int(input()) for _ in range(d)]).astype(np.int64)
    res = solve(d, c_arr, s_arr, t_arr)
    for r in res:
        print(r)


if __name__ == "__main__":
    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)]
t = [int(input()) for _ in range(d)]

lastd = [0]*26
point = 0

for j,k in enumerate(t):
    kk = k-1
    point += s[j][kk]
    lastd[kk] = j+1
    for l in range(26):
        point -= c[l]*(j+1-lastd[l])
    print(point)

Submission status: Accepted

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

last = [0 for _ in range(26)]
ans = 0
for i in range(D):
    contest = T[i] - 1
    ans += S[i][contest]
    d = i + 1
    last[contest] = d
    for x in range(26):
        ans -= C[x] * (d - last[x])
    print(ans)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s_matrix = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
last = [0] * 26
satis = 0

for i in range(D):
    test = t[i] - 1
    satis += s_matrix[i][test]
    last[test] = i + 1
    for j in range(26):
        satis -= c[j] * (i+1 - last[j])
    print(satis)

Submission status: Accepted

Solution code:
D=int(input())
c=list(map(int,input().split()))
s=[]
t=[]
last=[0]*26
v=0

for _ in range(D):
    ss=list(map(int,input().split()))
    s.append(ss)
for _ in range(D):
    tt=int(input())
    t.append(tt)

for d in range(D):
    last[t[d]-1]=d+1
    decrease=0
    for j in range(26):
        decrease+=c[j]*(d+1-last[j])
        
    v+=s[d][t[d]-1]-decrease
    print(v)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

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

def get_objective_function(output):
    objective_function = 0
    last = [[-1 for i in range(26)] for d in range(D)]

    for d in range(D):
        objective_function += s[d][output[d]]

        last[d][output[d]] = d
        if d < D-1:
            for i in range(26):
                last[d+1][i] = max(last[d][i], last[d+1][i])

        for i in range(26):
            objective_function -= c[i] * (d-last[d][i])
        print(objective_function)

    point = max(10 ** 6 + objective_function, 0)

## outputの作成
# IOに基づくパターン
output = []
for _ in range(D):
    output.append(int(input())-1)

# 最大効用での戦略
#output = []
#for d in range(D):
#    output.append(s[d].index(max(s[d])))
#for d in output:
#    print(d+1)

## 目的関数の確認
get_objective_function(output)

Submission status: Accepted

Solution code:
D = int(input())
C = [int(x) for x in input().split()]
S = [[int(i) for i in input().split()] for D in range(D)]
T = [0]*D
for i in range(D):
    T[i] = int(input())

score = [0]*26
last = [-1]*26

for i in range(D):
    score[T[i]-1] += S[i][T[i]-1]
    last[T[i]-1] = i

    for j in range(26):
        score[j] -= C[j]*(i-last[j])
    print(sum(score))

Submission status: Accepted

Solution code:
def score(day, contest, prev_list, loss_list, satisfied_matrix):
    plus = satisfied_matrix[day][contest]
    minus = 0
    for type, prev in enumerate(prev_list):
        spend = day - prev
        minus += loss_list[type] * spend

    return plus - minus



days = int(input())
loss_list = list(map(int, input().split()))
satisfied_matrix = [list(map(int, input().split())) for _ in range(days)]

prev_list = [-1] * 26

total = 0
for day in range(days):
    contest = int(input())
    prev_list[contest-1] = day
    total += score(day, contest-1, prev_list, loss_list, satisfied_matrix)
    print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 入力
D = int(input())

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

s_d_i = []
for d in range(D):
  s_d_i.append(list(map(int, input().split())))
  
last_i = []
for i in range(26):
  last_i.append(-1)
  
# tが入力の場合（Mainでは不要） 
t_d = []
for d in range(D):
  t_d.append(int(input()))
  
  
#scoring
r_sum = 0
for d in range(D):
  t = t_d[d] - 1

  #last更新
  last_i[t] = d
  
  #c
  c_sum = 0
  for i in range(26):
    c_sum += c_i[i] * (d - last_i[i])
  
  #s - c
  r_d = s_d_i[d][t] - c_sum
  r_sum += r_d
  print(r_sum)

Submission status: Accepted

Solution code:
import numpy as np
D = int(input())
C = list(map(int, input().split()))
B = np.array([0] * 26)
S = [list(map(int, input().split())) for _ in range(D)]
satisfaction = 0
for d in range(1, D+1):
    t = int(input())
    B[t-1] = d
    deduction = sum(C * (d - B))
    satisfaction += S[d-1][t-1] - deduction
    print(satisfaction)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	day_length = int(sys.stdin.readline())
	down_happy = list(map(int, sys.stdin.readline().split()))
	daily_happy = [[] for i in range(day_length)]
	contests_kind = 26
	contests = []
	for i in range(day_length):
		si = list(map(int, sys.stdin.readline().split()))
		for j in range(contests_kind):
			daily_happy[i].append(si[j])
	for i in range(day_length):
		contests.append(int(sys.stdin.readline())-1)
	log.print(day_length, down_happy, daily_happy)
	happy = 0
	last_contest_days = [0]*contests_kind
	for day in range(day_length):
		contest = contests[day]
		happy += daily_happy[day][contest]
		last_contest_days[contest] = day + 1
		for i in range(contests_kind):
			happy -= down_happy[i] * (day + 1 - last_contest_days[i])
		print(happy)





main()

Submission status: Accepted

Solution code:
import numpy as np
ans=0
D=int(input())
C=np.array(list(map(int,input().split())))
last_day=np.array([-1 for _ in range(26)])
score=np.array([list(map(int,input().split())) for _ in range(D)])

for day in range(D):
    t=int(input())-1
    last_day[t]=day
    tmp=C*(last_day-day)
    ans=ans+score[day][t]+sum(tmp)
    print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

input = sys.stdin.readline

D = int(input())
c = np.array(list(map(int, input().split())), dtype=int)
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype=int)
T = np.array([int(input()) for _ in range(D)], dtype=int)
dissatis = np.zeros(26, dtype=int)

v = 0
for i, (s, t) in enumerate(zip(S, T)):
    v += s[t-1]
    dissatis += c
    dissatis[t-1] = 0
    v -= np.sum(dissatis)
    print(v)

Submission status: Accepted

Solution code:
D = int(input())
C = input().split()
C = [int(c) for c in C]
#print(C)
S = []
for i in range(D):
  s = input().split()
  s = [int(j) for j in s]
  S.append(s)
M = 0
last = [0] * 26
#print(last)
for d in range(1,D+1):
  N = 0
  t = int(input())
  last[t-1] = d
  #print(last)
  for j in range(26):
    N = N + C[j]*(d-last[j])
  M = M + S[d-1][t-1] - N
  print(M)

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()) - 1 for _ in range(D)]

S = 0
last = [-1] * 26
score = 0
for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S -= c[i] * (d - last[i])
    score += max(10 ** 6 + S, 0)
    print(S)

Submission status: Accepted

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


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:
d = int(input())
cList = input().split()

sList = []

for idx in range(0, d):
    tempList = input().split()
    sList.append(tempList)

tList = []

for idx in range(0, d):
    tList.append(int(input()))

countList = [0] * 26
val = 0

for idx in range(0, d):
    val += int(sList[idx][tList[idx] -1])

    countList = list(map(lambda x: x+1, countList))
    countList[int(tList[idx]) -1] = 0

    for wkChar in range(0,26):
        val -= int(countList[wkChar]) * int(cList[wkChar])
    print(val)