NC5158 G-做题

做题

https://ac.nowcoder.com/acm/contest/5158/G

Question

有 nn 个题目,mm 分钟,做完每个题目所花费的时间是不一样的,求牛可乐最多可以做出多少个题目。

Solution

简单贪心
排个序,从小到大。

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 5e5 + 5;

ll n,m,a[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    ll cnt=0;
    for(int i=1;i<=n;i++){
        if(m>=a[i]){
            m-=a[i];
            cnt++;
        }else{
            break;
        }
    }
    cout<<cnt<<'\n';
    return 0;
}
全部评论

相关推荐

06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
求offer的大角牛:简历写的第一乱,没有突出重点,第二项目太多太杂看不出来有啥核心技术,第三自我评价太多了,第四获得的荣誉没啥含金量,可以不写,反正问题不少
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务