codeforces 913D Too Easy Problems
http://www.elijahqi.win/2018/01/09/codeforces-913d-too-easy-problems/
D. Too Easy Problems
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 j between 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 ≤ n; 1 ≤ 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.
題意:給定每個 任務的a[]和t[]分別表示 這場考試 整體做了多少題 如果<=a[i]那麼他就可以給我 最後加分+1 如果 >a[i] 就不加分了 那麼 我就每次去貳分一下 我做了多少題 然後 每次去判斷的時候 如果我a[i]< mid那麼就不新增進去 否則新增到佇列裡 然後都選出來之後 貪心的選一下看 如果這麼少的時間我能否湊夠我要的mid個 %%%%icefox 太強啦 qwq我哪會啊 要不是他提醒 我差一點就掉分了
然後最後輸出方案的時候因為我已經知道答案了 再和貳分驗證的時候一樣我去輸出即可
#include<cstdio>
#include<algorithm>
#define N 220000
using namespace std;
int n,T,a[N],t[N],q[N];
struct node{
int id,t;
}qq[N];
inline bool cmp(node a,node b){return a.t<b.t;}
inline bool check(int mid){
int num=0;
for (int i=1;i<=n;++i) if(a[i]>=mid) q[++num]=t[i];
sort (q+1,q+num+1);int x=0;if(num<mid) return 0;int time=0;
for (int i=1;i<=num;++i){
if(time+q[i]>T) break;
++x;time+=q[i];if (x>=mid) return 1;
}return x>=mid;
}
int main(){
freopen("cf.in","r",stdin);
scanf("%d%d",&n,&T);
for (int i=1;i<=n;++i) scanf("%d%d",&a[i],&t[i]);
int l=0,r=n;
while(l<=r){
int mid=l+r>>1;
if (check(mid)) l=mid+1;else r=mid-1;
}printf("%d\n",r);printf("%d\n",r);int num=0;
for (int i=1;i<=n;++i) if (a[i]>=r) qq[++num].t=t[i],qq[num].id=i;
sort(qq+1,qq+num+1,cmp);for (int i=1;i<=r;++i) printf("%d ",qq[i].id);
return 0;
}
相關推薦
codeforces 913D Too Easy Problems
http://www.elijahqi.win/2018/01/09/codeforces-913d-too-easy-problems/ D. Too Easy Problems time limit per test 2 seconds memo
Codeforces Hello 2018 D. Too Easy Problems 二分+貪心
D. Too Easy Problems time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard out
Hello 2018 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 p
D. Too Easy Problems(二分,排序,貪心)
題目大意:給出n個問題和總時間t。給出的n個問題,對於每個問題都有一個限制題數,如果答題數超過了該題的限制題數,該題不得分;以及每道題所需要花費的時間。現在要求再規定時間內儘可能的拿高分。輸出結果不唯一,即順序不唯一,以及規定時間內做的不得分的題可算可不算。思路:二分,排序,
「AGC005F」Many Easy Problems-NTT
Description 連結 Solution 考慮每個點 u u u的貢獻對
AGC005F Many Easy Problems
題目 你有一棵無根樹(n個結點,1~n標號),和一個整數k。 對於一個樹上的結點集合S,可以用一個子樹把S中的點全部包含,這裡子樹指的是原樹結點的一個子集,並且這些結點全部連通。對於集合S,令f(S)表示這樣的子樹最少所包含的結點數目。 共有C(n,k)種
【Codeforces 1096D】Easy Problem
throw 序列 string print void set out ack java 【鏈接】 我是鏈接,點我呀:) 【題意】 讓你將一個字符串刪掉一些字符。 使得字符串中不包含子序列"hard" 刪掉每個字符的代價已知為ai 讓你求出代價最
Lucky Numbers (easy) CodeForces - 96B
doesn sample repr pan algorithm his red ica cif Petya loves lucky numbers. Everybody knows that positive integers are lucky if their deci
Codeforces 71A Way Too Long Words
div problems 題目 space ostream mes -- AS bsp 題目鏈接 http://codeforces.com/problemset/problem/71/A #include<iostream> #include<str
Codeforces Round #519 by Botan Investments E. Train Hard, Win Easy(思維+貪心)
題目連結 題意 每個人都可以解決A題和B題,得分分別是 x i
【Codeforces Round #519 by Botan Investments E】Train Hard, Win Easy
【連結】 我是連結,點我呀:) 【題意】 【題解】 設每個人做第一題、第二題的分數分別為x,y 我們先假設沒有仇視關係。 即每兩個人都能進行一次訓練。 那麼 對於第i個人。 考慮第j個人對它的貢獻 如果xi+yj<yi+xj 即xi-yi<xj-yj 也就是說,如果我們以
【Codeforces Round #519 by Botan Investments - E. Train Hard, Win Easy】排序+字首和
Codeforces Round #519 by Botan Investments - E. Train Hard, Win Easy 題意 有 兩
Codeforces 1077F1 Pictures with Kittens (easy version)(DP)
題目連結:Pictures with Kittens (easy version) 題意:給定n長度的數字序列ai,求從中選出x個滿足任意k長度區間都至少有一個被選到的最大和。 題解:$dp[i][j]$:以i為結尾選擇j個數字的最大和。 $dp[i][j]=max(dp[i][j],dp[s][j-1
codeforces 1043 E. Train Hard, Win Easy
題目傳送門 題意: 有n個人,m個排斥關係,有一個競賽,有兩道題目,給出n個人做兩道題的做題速度,然後求分別這n個人做題時間累積的最小值。每個人只能做一道題,下一個題目必須他的同伴來做。有排斥關係的兩個人不能相互組隊。 思路: 設i的做題時間分別為xi,yi,j的做題時間分別為xj,yj。
Codeforces 1089E - Easy Chess - [DFS+特判][2018-2019 ICPC, NEERC, Northern Eurasia Finals Problem E]
題目連結:https://codeforces.com/contest/1089/problem/E Elma is learning chess figures. She learned that a rook can move either horizontally or vertically. To
Codeforces Round #512(Technocup 2019 Elimination Round 1) A. In Search of an Easy (Codeforces 1030A)
題意:給出一個01串,如果全0則輸出EASY,否則輸出HARD。 思路:入門題……迴圈下就好 程式碼: #include<bits/stdc++.h> using namespace st
codeforces cf educatonal round 57(div2) D. Easy Problem
這道題用滾動陣列比較好寫。dp[i]表示當前字母不形成hard前i個字母組成的子串的最小代價。每次更新dp[i],考慮兩種情況,第一種是當前可能放在hard的第i個字母上,那麼我們更新dp值為dp[i]+a[i];第二種是前i-1個字母都沒有構成的最小代價,用dp[i-1]更新,兩者取最小值 #inc
Codeforces Beta Round #77 (Div. 2 Only)B. Lucky Numbers (easy)
題意 尋找一個最小的 大於n的super lucky數字,super lucky數字時只含4和7。 思路 最初想著拼湊,找規律,沒辦法只有DFS了, INF設的太小wa,ans會超int ans的臨時變數tem忘開long long又wa AC Code
Codeforces Gym 100623J Problem J. Just Too Lucky 數位DP
題解:數位DP經典題目,先暴力一遍,把可能出現的各位數字和都跑一遍,然後就是經典數位DP了,記憶化搜尋寫完的,詳見程式碼 Code: #include <iostream> #include <cstdio> #include <cst
Codeforces 320B Ping-Pong (Easy Version)
題意:先輸入n,接下來輸入n行,每行輸入三個數,q,a,b,若q==1,則新增一個區間(a,b)。若q==2,表示查詢第a個區間能否到達第b個區間。注意: 區間a:(x,y)能到區間b(c,d)的條件是: c < x < d || c &