列表

详情


NC232324. Ah, Tenshi!

描述

Tenshi is a CS student in SUSTech with an initial coding level .


Tenshi meets  coders in the campus, the  of which has a coding level .

He can choose to challenge some or all of these N coders in any order he wants.

If his current coding level is greater than the coder he challenges, Tenshi's coding level will be increased by that coder's coding level.

Tenshi can challenge each coder at most once.


Tenshi would be grateful if you tell him the maximum coding level he can achieve.

输入描述

The input consists of:

    One line containing two integers N, C seperated by a space.

    One line containing N integers  seperated by spaces.


输出描述

Output a single integer indicating the maximum coding level Tenshi can achieve.

示例1

输入:

5 2
3 1 15 2 2

输出:

10

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 317ms, 内存消耗: 3448K, 提交时间: 2022-03-12 12:39:35

#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int main(){
long long ans,n;
cin>>n>>ans;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++){
    if(ans>a[i])ans+=a[i];
}
cout<<ans<<endl;
}

pypy3 解法, 执行用时: 653ms, 内存消耗: 107180K, 提交时间: 2021-12-26 14:29:16

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

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

a.sort()

for i in range(n):
    if c > a[i]:
        c += a[i]
print(c)        

Python3 解法, 执行用时: 674ms, 内存消耗: 94740K, 提交时间: 2021-12-26 18:31:09

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in a:
    if m<=i:
        break
    m+=i
print(m)

上一题