D


私信TA

用户名:ALS1111

访问量:19492

签 名:

等  级
排  名 51
经  验 10951
参赛次数 0
文章发表 132
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

python-乘积最大
浏览:203
python-回文数
浏览:176
python-摆花摆花
浏览:119

解题思路:

注意事项:

参考代码:

from cmath import inf    
     
     
n,k = map(int,input().strip().split())    
A = [int(i) for i in input().strip().split()]    
B = [[-inf for j in range(3)] for i in range(k)]    
     
for i in A:    
    temp = i % k    
    if i > B[temp][0]:    
        B[temp][2] = B[temp][1]    
        B[temp][1] = B[temp][0]    
        B[temp][0] = i    
    elif i > B[temp][1]:    
        B[temp][2] = B[temp][1]    
        B[temp][1] = i    
    elif i > B[temp][2]:    
        B[temp][2] = i    
     
maxnum = -inf  
for i in range(0,k):    
    for j in range(i,k):    
        temp = (k - i - j) % k    
                 
        if len(set([i,j,temp])) == 2 and i == j:    
            num = B[i][0]+B[i][1]+B[temp][0]    
            if maxnum < num:    
                maxnum = num    
        elif len(set([i,j,temp])) == 2 and i == temp:    
            num = B[i][0]+B[i][1]+B[j][0]    
            if maxnum < num:    
                maxnum = num    
        elif len(set([i,j,temp])) == 2 and j == temp:    
            num = B[i][0]+B[j][0]+B[j][1]    
            if maxnum < num:    
                maxnum = num    
        elif len(set([i,j,temp])) == 3:    
            num = B[i][0]+B[j][0]+B[temp][0]    
            if maxnum < num:    
                maxnum = num    
     
print(maxnum)


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区