F1. Complete the Projects (easy version)

F2. Complete the Projects (hard version)

参考:Complete the Projects

简单说就是当 b>=0 是肯定是 a 小的优先的,需要注意的就是 b<0,的情况,结论:a+b 大的优先(证明看参考博客)

需要用到的算法:贪心和 dp

代码(只贴 F2 的了,F1 改一点点就行):

// Created by CAD on 2019/8/14.
#include <bits/stdc++.h> #define fi first
#define se second
#define inf 0x3f3f3f3f
using namespace std;
using pii=pair<int, int>;
using piii=pair<pair<int, int>, int>;
using ll=long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
vector<pii>pos,neg;
int n,r;
cin>>n>>r;
for(int i=1,a,b;i<=n;++i)
{
cin >> a >> b;
if(b>=0)
pos.push_back({a,b});
else neg.emplace_back(a+b,a);
}
sort(pos.begin(),pos.end());
sort(neg.begin(),neg.end());
reverse(neg.begin(),neg.end());
int cnt=0;
for(auto p:pos)
if(r<p.fi) break;
else r+=p.se,cnt++;
vector<int>dp(r+1,-inf);
dp[r]=cnt;
for(auto p:neg)
{
int a=p.se,b=p.fi-p.se;
for(int i=max(a,-b);i<=r;++i)
dp[i+b]=max(dp[i+b],dp[i]+1);
}
for(int i=0;i<=r;++i)
cnt=max(cnt,dp[i]);
cout<<cnt<<endl;
}

Complete the Projects的更多相关文章

  1. CF1203F2 Complete the Projects (hard version)(结论+背包+贪心)

    题目 做法 对于加分的直接贪心 而掉分的用排序后的背包动规 假设有两个物品\((a_1,b_1)(a_2,b_2)\) 选第一个物品后无法选择第二个物品,假设开始值为\(r\):\(r>a_1, ...

  2. Codeforces 1203F2. Complete the Projects (hard version)

    传送门 首先对于 $b>0$ 的工作显然有个贪心,把 $b>0$ 的按 $a$ 从小到大排序 把能做的都做了,然后得到一个最大等级 剩下就是考虑 $b<0$ 的工作了,看到数据显然可 ...

  3. Codeforces1203F2. Complete the Projects (hard version) (贪心+贪心+01背包)

    题目链接:传送门 思路: 对于对rating有提升的项目,肯定做越多越好,所以把$b_{i} >= 0$的项目按rating要求从小到大贪心地都做掉,得到最高的rating记为r. 对于剩余的$ ...

  4. Codeforces 1203F1 Complete the Projects (easy version)

    cf题面 Time limit 2000 ms Memory limit 262144 kB 解题思路 看见这题觉得贪心可做,那就贪吧.(昨天真是贪心的一天,凌晨才被这两道贪心题虐,下午多校又来,感觉 ...

  5. Codeforces Round #579 (Div. 3) Complete the Projects(贪心、DP)

    http://codeforces.com/contest/1203/problem/F1 Examples input 1 - - output 1 YES input 2 - - output 2 ...

  6. P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

    P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May ...

  7. 微软职位内部推荐-Senior Data Scientist

    微软近期Open的职位: Extracting accurate, insightful and actionable information from data is part art and pa ...

  8. Codeforces Round #579 (Div. 3)

    Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...

  9. Gerrit - 代码评审工具Gerrit简介与安装

    1 - 前言 Code Review 代码评审是指在软件开发过程中,对源代码的系统性检查,改进代码质量,查找系统缺陷,保证软件总体质量和提高开发者自身水平. 简单的说,Code Review是用来确认 ...

随机推荐

  1. 易百教程人工智能python修正-人工智能数据准备-预处理数据

    预处理数据 在我们的日常生活中,需要处理大量数据,但这些数据是原始数据. 为了提供数据作为机器学习算法的输入,需要将其转换为有意义的数据. 这就是数据预处理进入图像的地方. 换言之,可以说在将数据提供 ...

  2. iOS - 适配iOS 11

    http://www.10tiao.com/html/330/201707/2653579210/1.html 存档 导语:iOS 11 为整个生态系统的 UI 元素带来了一种更加大胆.动态的新风格. ...

  3. VS2017 Git failed with a fatal error. error: open(".vs/xxxxxx/v15/Server/sqlite3/db.lock"): Permission denied fatal: Unable to process path .vs/xxxxxx/v15/Server/sqlite3/db.lock

    具体错误信息:Git failed with a fatal error. error: open(".vs/xxxxxx/v15/Server/sqlite3/db.lock") ...

  4. PHP/Python---百钱百鸡简单实现及优化

    公鸡5块钱一只,母鸡3块钱一只,小鸡一块钱3只,用100块钱买一百只鸡,问公鸡,母鸡,小鸡各要买多少只? 今天看到这题很简单 ,但是随手写出来后发现不是最优的

  5. vue入门模板——只需一个html

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. SQL统计部门人数,人数为0的部门也要显示出来

    相同点:它们都以一张部门表(或类别表),其它表都有部门编号DepartmentID(类别编号) 案例一:一张表 select c.DepartmentID,c.DepartmentName, t.Nu ...

  7. Qt命名规范

    1) 类名:单词首字母大写,单词和单词之间直接连接,无需连接字符 如: MyClass,QPushButton class MainWindow { }; 2) 函数名字,变量名:第二个单词开始(不是 ...

  8. (三)WCF之契约

    自从我们接收ITOO项目之后,就必须跟WCF打交道,既然必须直面WCF,我就对WCF进行了研究(还不是很深入,是自己目前的理解).之前对WCF的一些基础知识进行了简单的介绍,本篇重点来介绍WCF的契约 ...

  9. vm.$attrs与inheritAttrs详解

    1. inheritAttrs 在vue官网的解释如下 个人理解:父组件A上引入子组件B,在B子组件上加上一些属性(class.style除外),这些属性能否在子组件B的根元素上继承,默认值为true ...

  10. ASCII、Unicode、UTF-8字符集编码

    ASCII码 计算机内部,所有信息都是由二进制的字符串表示 每一个二进制位有“0”.“1”两种状态,因此8个二进制位可以表示256个状态,每个状态代表一个符号就是256个符号,从0000000到111 ...