zoukankan      html  css  js  c++  java
  • Hello 2018 D

    D. Too Easy Problems
     

    You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either.

    Unfortunately, your teacher considers some of the problems too easy for you. Thus, he assigned an integer ai to every problem i meaning that the problem i can bring you a point to the final score only in case you have solved no more than ai problems overall (including problem i).

    Formally, suppose you solve problems p1, p2, ..., pk during the exam. Then, your final score s will be equal to the number of values of jbetween 1 and k such that k ≤ apj.

    You have guessed that the real first problem of the exam is already in front of you. Therefore, you want to choose a set of problems to solve during the exam maximizing your final score in advance. Don't forget that the exam is limited in time, and you must have enough time to solve all chosen problems. If there exist different sets of problems leading to the maximum final score, any of them will do.

    Input

    The first line contains two integers n and T (1 ≤ n ≤ 2·105; 1 ≤ T ≤ 109) — the number of problems in the exam and the length of the exam in milliseconds, respectively.

    Each of the next n lines contains two integers ai and ti (1 ≤ ai ≤ n1 ≤ ti ≤ 104). The problems are numbered from 1 to n.

    Output

    In the first line, output a single integer s — your maximum possible final score.

    In the second line, output a single integer k (0 ≤ k ≤ n) — the number of problems you should solve.

    In the third line, output k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the indexes of problems you should solve, in any order.

    If there are several optimal sets of problems, you may output any of them.

    Examples
    input
    5 300
    3 100
    4 150
    4 80
    2 90
    2 300
    output
    2
    3
    3 1 4
    input
    2 100
    1 787
    2 788
    output
    0
    0

    input
    2 100
    2 42
    2 58
    output
    2
    2
    1 2
    Note

    In the first example, you should solve problems 3, 1, and 4. In this case you'll spend 80 + 100 + 90 = 270 milliseconds, falling within the length of the exam, 300 milliseconds (and even leaving yourself 30 milliseconds to have a rest). Problems 3 and 1 will bring you a point each, while problem 4 won't. You'll score two points.

    In the second example, the length of the exam is catastrophically not enough to solve even a single problem.

    In the third example, you have just enough time to solve both problems in 42 + 58 = 100 milliseconds and hand your solutions to the teacher with a smile.

    有n个题目,时间为t

    在t时间内求最多能得到的分数,a,t表示在完成这个任务时不能超过a个任务,t是不能超过这个时间。

    是求最大分数,那么可以从n依次递减,直到符合就是最大积分了。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int N = 2e5+10;
     4 vector<pair<int,int> > vs[N];
     5 priority_queue<pair<int, int> > que;
     6 int main() {
     7     int n, t;
     8     cin >> n >> t;
     9     for(int i = 1; i <= n; i ++) {
    10         int x, y;
    11         cin >> x >> y;
    12         vs[x].push_back(make_pair(y,i));
    13     }
    14     int sum = 0;
    15     for(int i = n; i >= 0; i --) {
    16         for(int j = 0; j < vs[i].size(); j ++) {
    17             que.push(vs[i][j]);
    18             sum += vs[i][j].first;
    19         }
    20         while(que.size() > i) {
    21             sum -= que.top().first;
    22             que.pop();
    23         }
    24         if(que.size() == i && sum <= t) {
    25             printf("%d
    %d
    ",i,i);
    26             while(!que.empty()) {
    27                 printf("%d ",que.top().second);
    28                 que.pop();
    29             }
    30             printf("
    ");
    31             break;
    32         }
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    Edit Distance编辑距离(NM tag)- sam/bam格式解读进阶
    《开讲啦》 20160910 颜宁:女科学家去哪儿了?
    pysam
    Python项目实战
    最小二乘估计法
    最大似然估计(Maximum Likelihood,ML)
    HMM隐马尔科夫模型
    贝叶斯推断|朴素贝叶斯分类|贝叶斯定理
    解决“tar:Exiting with failure status due to previous errors”【转】
    df -h执行卡住不动问题解决【转】
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8269688.html
Copyright © 2011-2022 走看看