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;
    }
  • 相关阅读:
    jquery自调用匿名函数解析
    C# 分页
    C#一般处理程序获取Session
    Python全栈开发,Day12
    Python全栈开发,Day11
    Python全栈开发,Day10
    Python全栈开发,Day9
    Python全栈开发,Day8
    Python全栈开发,Day7
    Python全栈开发,Day6
  • 原文地址:https://www.cnblogs.com/BriMon/p/9439201.html
Copyright © 2011-2022 走看看