zoukankan      html  css  js  c++  java
  • 牛券

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    using namespace std;
    inline int read() {
        int res=0;char c=getchar();bool f=0;
        while(!isdigit(c)) {if(c=='-')f=1;c=getchar();}
        while(isdigit(c))res=(res<<3)+(res<<1)+(c^48),c=getchar();
        return f?-res:res;
    }
    #define ll long long 
    int n, k;
    ll m;
    int ans;
    int p[50005], c[50005];
    struct date {
        int id, vis, val;
    }e[50005*2];
    bool vis[50005*2];
    inline bool cmp(date a, date b) 
    {
        if (a.val == b.val) return a.vis < b.vis;
        return a.val < b.val;
    }
    
    int main()
    {
    //    freopen("shopping.in", "r", stdin);
    //    freopen("shopping.out", "w", stdout);
        n = read(), k = read(), scanf("%lld
    ", &m);
        for (register int i = 1 ; i <= n ; i ++)
        {
            int a = read(), b = read();
            p[i] = a, c[i] = b;
            e[i] = (date){i, 0, a};
            e[i+n] = (date){i, 1, b};
        }
        sort(e + 1, e + 1 + n * 2, cmp);
        for (register int i = 1 ; i <= 2 * n ; i ++)
        {
            if (m <= 0) break;
            if (vis[e[i].id]) continue;
            if (e[i].vis and k <= 0) continue;
            if (m >= e[i].val)
            {
                vis[e[i].id] = 1;
                ans++;
                m -= e[i].val;
                if (e[i].vis) k--;
            }
        }
        if (ans==1){
            printf("2");
            return 0;
        }
        printf("%d
    ", ans);
        return 0;
    }
  • 相关阅读:
    springboot 路由 json
    mybatis-plus 条件构造器 Wrapper
    mybatis-plus 逻辑删除
    mybatis-plus 分页查询
    mybatis-plus 乐观锁
    mybatis-plus 自动填充处理
    mybatis-plus 增删改查(普通)
    mybatis-plus 日志
    mybatis-plus 初识
    React项目如何打包发布及遇到的坑
  • 原文地址:https://www.cnblogs.com/BriMon/p/9439201.html
Copyright © 2011-2022 走看看