题解 | 多米诺骨牌

多米诺骨牌

https://www.nowcoder.com/practice/0757b8571cd047aab5dea52c1f369e55

#include<bits/stdc++.h>
#define pii pair<int,int>

using namespace std;

const int N = 2e5+5;

int T;
int n,m;

struct node{
    int h;
    int x;
    bool operator<(const node& c)const{
        return x < c.x;
    }
}pos[N];

inline void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>pos[i].h;
    for(int i=1;i<=n;i++) cin>>pos[i].x;
    vector<int>v;
    sort(pos+1,pos+n+1);
    int l = 0, r= 0;
    int cnt = 0;
    for(int i=1;i<=n;i++){
        if(pos[i].x > r) {
        v.push_back(cnt);
        l = pos[i].x;
        r = pos[i].x + pos[i].h;
        cnt = 1;
        }
        else{
            r = max(r,pos[i].x + pos[i].h);
            cnt++;
        }
    }
    v.push_back(cnt);
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    int scnt = 0, ans = 0;
    for(int i:v){
        scnt++;
        ans += i;
        if(scnt == m) break;
    }
    //for(int i:v) cout<<i<<' ';
    cout<<ans<<'\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--) solve();
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
白火同学:先说结论,对于一份实习简历来说,整体还是挺不错的,技术深度和广度都到位,找到一份中小厂的实习没啥问题。 再说说能优化的点吧。 1、量化结果,项目中很多工作量化一下结果给面试官的感受会更直观一些,也能体现你对应用该项技术的理解(在众多技术为什么要用它,运行性能或者说开发效率往往是一大考虑指标;而不是说大家做这种功能都用它,所以我用它)。 2、突出亮点,项目中可以从“工作职责”择一些“个人亮点”另写一块,优先去写开发过程中遇到的xx问题,使用xx技术达到xx效果,针对性去写一些疑杂难的功能,能带出你个人思考和解决的过程。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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