problem AOR Ika-chan is taking a class where grades are determined only by the score of…
- User
problem
AOR Ika-chan is taking a class where grades are determined only by the score of the report. AOR Ika-chan has friends who are taking the same class, and if you have a report on a theme that you are not good at, you can get the same score as that friend by copying the report of a friend who is good at that theme. .. However, the teacher should not be aware that you are copying someone else's report, so you have to finish the report yourself, not copying someone else's report at least out of times. Also, AOR Ika didn't want to bother her friends, so she decided to copy the report to her friend less than times. Answer the maximum total score that AOR Ika can get when given the score when AOR Ika finishes the report by herself and the score when her friend finishes the report. input
Assistant
def main(): import sys input = sys.stdin.read().split() ptr = 0 N, M, K = map(int, input[ptr:ptr+3]) ptr +=3 a = list(map(int, input[ptr:ptr+N])) ptr +=N b = [] for _ in range(M): b.append(list(map(int, input[ptr:ptr+N]))) ptr +=N T = list(map(int, input[ptr:ptr+M])) ptr +=M # For each report j, find the best friend and delta best_delta = [] for j in range(N): max_d = 0 best_i = -1 for i in range(M): if b[i][j] > a[j]: delta = b[i][j] - a[j] if delta > max_d: max_d = delta best_i = i if max_d >0: best_delta.append( ( -max_d, j, best_i ) ) # Use negative for min-heap # Sort the best_delta in descending order of delta best_delta.sort() best_delta = [ (-d, j, i) for d, j, i in best_delta ] copies_available = T.copy() total_copies =0 total_gain =0 for d, j, i in best_delta: if total_copies >= (N - K): break if copies_available[i] >0: total_gain +=d copies_available[i] -=1 total_copies +=1 sum_a = sum(a) print(sum_a + total_gain) if __name__ == '__main__': main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.