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. 并发编程之Disruptor并发框架

    一.什么是Disruptor Martin Fowler在自己网站上写了一篇LMAX架构的文章,在文章中他介绍了LMAX是一种新型零售金融交易平台,它能够以很低的延迟产生大量交易.这个系统是建立在JV ...

  2. DML 操作表中数据

    DML 是对于表中的记录进行增删改操作 一.添加数据   语法格式: insert into 表名[字段名] values[字段值]      表名:表示往那张表中添加数据   (字段名1,字段名2, ...

  3. [TensorFlow]Windows下安装并运行Hello World

    参考网址:https://www.tensorflow.org/install/pip (或要VPN) 建议电脑是独显N卡机,安装前先升级驱动,减少不必要错误 1.下载Microsoft Visual ...

  4. vs code 调试设置

    首先vs code 安装插件:Debugger for Chrome vscode 设置:点击调试按钮,然后调试面板界面再点击设置按钮,添加一个配置,选择环境为:chrome编辑器自动生成一个laun ...

  5. SAP Marketing Cloud功能简述(五) : 销售计划管理

    Grace前四篇介绍SAP Marketing Cloud的文章: SAP Marketing Cloud功能简述(一) : Contacts和Profiles SAP Marketing Cloud ...

  6. redis 异常 MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk

    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. 解决方 ...

  7. pod健康检查(liveness probe存活探针&&readiness probe 可读性探针)

    在Kubernetes集群当中,我们可以通过配置liveness probe(存活探针)和readiness probe(可读性探针)来影响容器的生存周期.参考文档:https://kubernete ...

  8. 【HICP Gauss】数据库 环境的搭建 -1

    1.安装规则    1.主机名必须网络唯一  2.主机名必须两位数以上 可以中划线 不能下划线  3.固定IP地址  4.端口号 1888 新增账户 omm 用户组 dbgrp ,家目录 /home/ ...

  9. ISCC之msc4

    一开始拿到题目的时候有点懵的,给个gif图片,233 常规分析,gif打开看一看,发现gif是多张图片组成,于是用fastStone Image viewer分解成九张图片 后面用PS拼起来,得到一个 ...

  10. qingqing的项目

    1 https://www.cnblogs.com/zhangqing979797/p/10147679.html 2 https://www.cnblogs.com/zhangqing979797/ ...