Problem: Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:    * For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).    * Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.  Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.  Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, **he cannot score more than X on an exam**, since the perfect score for all the exams is X.  Print the minimum number of study hours required for Takahashi to win.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**7)
import numpy as np
np.set_printoptions(suppress=True)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())


debug = True
#debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    n, x = map(int, input().split())
    # b_list = []
    # l_list = []
    # u_list = []
    # b, l, u, eff
    data = np.zeros(shape=(n, 6))

    # eff_list = []
    for i in range(n):
        b, l, u = map(int, input().split())
        base_minus = b * l 
        max_plus = (x-b) * u 
        eff = max_plus + base_minus 
        data[i] = [b, l, u, eff, max_plus, base_minus]

    eff_argsort = np.argsort(data[:, 3])[::-1]
    dprint(data[eff_argsort])

    total_time = 0
    total_score = -1*np.sum(data[:, 5]) 
    dprint(total_score)

    import math
    for i in range(n):
        d = data[eff_argsort][i]
        # b = d[0]
        # l = d[1]
        
        # eff = d[3]
        
        # base_minus = d[5]

        total_score_tmp = total_score
        if total_score < 0:
            total_score_tmp += d[3]

        
        if total_score_tmp < 0:
            
            total_score = total_score_tmp
            total_time += x
            dprint(i, total_score, total_time)
        else:
            
            
            dprint("ajusting")
            dprint(total_time, total_score)
            rest_data = data[i:] 
            dprint(rest_data)
            rest_time = (-1*total_score - rest_data[:, 5]) / rest_data[:, 2] + rest_data[:, 0] 
            dprint(rest_time)
            total_time += math.ceil(min(rest_time))
            break

    print(int(total_time))


solve()

import sys
import math
import numpy as np
sys.setrecursionlimit(10**7)

class Task:
    def __repr__(self):
        return str(self.__dict__)

    def time_toget_point(self, p):
        
        if p >= self.max_minus:
            return math.ceil(self.b + (p - self.max_minus)/self.u)
        else:
            return math.ceil(p/self.l)

def solve():
    n, x = map(int, input().split())
    t_list = []
    total_behind = 0 

    for i in range(n):
        t = Task()
        t.b, t.l, t.u = map(int, input().split())
        t.max_minus = t.b * t.l
        t.eff = ((x-t.b)*t.u) + (t.b*t.l) 
        t_list.append(t)
        total_behind += t.max_minus

    
    t_list = sorted(t_list, key=lambda t: t.eff, reverse=True)
    cumsum = list(np.cumsum([t.eff for t in t_list]))

    
    import bisect
    for max_i in range(len(t_list)):
        if cumsum[max_i] > total_behind:
            break

    
    min_time = -1
    for i, t in enumerate(t_list):
        if i <= max_i:
            
            rest_p = total_behind - (cumsum[max_i] - t.eff)
        else:
            
            
            if max_i == 0:
                rest_p = total_behind
            else:
                rest_p = total_behind - cumsum[max_i-1]

        
        time = x * (max_i) + t.time_toget_point(rest_p)

        if min_time == -1 or min_time > time:
            min_time = time
    print(min_time)

solve()

Verdicts: Wrong Answer

Accepted