Problem: Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.  There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.  What is the minimum amount of money with which he can buy M cans of energy drinks?  It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

Submission attempts (in order):
# -*- coding: utf-8 -*-                                                                                 
import sys, heapq                                                                                       
# ----------------------------------------------------------------                                      
# Use Solve Function                                                                                    
                                                                                                        
def solve(lines):                                                                                       
    N,M = map(int, lines.pop(0).split(' '))                                                             
    NLIST = []                                                                                          
    for i in range(N):                                                                                  
        A,B = map(int, lines.pop(0).split(' '))                                                         
        heapq.heappush(NLIST, (A, B))                                                                   
                                                                                                        
    res = 0                                                                                             
    while(True):                                                                                        
        p = heapq.heappop(NLIST)                                                                        
        if ( p[1] >= M ):                                                                               
            res += M * p[0]                                                                             
            break                                                                                       
        else:                                                                                           
            res += p[0] * p[1]                                                                          
            M -= p[1]                                                                                   
                                                                                                        
                                                                                                        
    print(res)                                                                                          
lines = contents.split('\n')                                                                            
                                                                                                        

                                                                                                        
lines = [x.strip() for x in sys.stdin.readlines()]                                                      
                                                                                                        
#                                                                                                       
# solve !!                                                                                              
#                                                                                                       
solve(lines) 

# -*- coding: utf-8 -*-                                                                                 
import sys, heapq                                                                                       
# ----------------------------------------------------------------                                      
# Use Solve Function                                                                                    
                                                                                                        
def solve(lines):                                                                                       
    N,M = map(int, lines.pop(0).split(' '))                                                             
    NLIST = []                                                                                          
    for i in range(N):                                                                                  
        A,B = map(int, lines.pop(0).split(' '))                                                         
        heapq.heappush(NLIST, (A, B))                                                                   
                                                                                                        
    res = 0                                                                                             
    while(True):                                                                                        
        p = heapq.heappop(NLIST)                                                                        
        if ( p[1] >= M ):                                                                               
            res += M * p[0]                                                                             
            break                                                                                       
        else:                                                                                           
            res += p[0] * p[1]                                                                          
            M -= p[1]                                                                                   
                                                                                                        
                                                                                                        
    print(res)                                                                                          
                                                                                                        
lines = [x.strip() for x in sys.stdin.readlines()]                                                      
                                                                                                        
#                                                                                                       
# solve !!                                                                                              
#                                                                                                       
solve(lines) 

Verdicts: Runtime Error

Accepted