Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)

HID报告描述符实战解析:从Usage到Item的完整设计流程 本文深入解析了HID报告描述符的设计流程,从核心概念Usage(用途定义)入手,详细阐述了如何通过Item(条目)的三种角色——全局、局部与主干,构建出能被系统正确识别的设备“说明书”。文章以标准USB鼠标和键盘为例进行实战拆解,并介绍了使用Report ID与自定义设备等进阶设计方法,帮助开发者掌握这一实现USB设备即插即用的关键技术。 阅读详情

B. Valera and Fruits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera loves his garden, where n fruit trees grow.

This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).

Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more thanv fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?

Input

The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.

Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi(1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.

Output

Print a single integer — the maximum number of fruit that Valera can collect.

Sample test(s)
input
2 3
1 5
2 3
output
8
input
5 10
3 20
2 20
1 20
4 20
5 20
output
60
Note

In the first sample, in order to obtain the optimal answer, you should act as follows.

  • On the first day collect 3 fruits from the 1-st tree.
  • On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
  • On the third day collect the remaining fruits from the 2-nd tree.

In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.


题目链接:http://codeforces.com/contest/441/problem/B


题目大意:有n棵果树和每天最大的水果采摘量v,每棵果树有对应的采摘日期day,只能在day和day+1两天采摘,求最终水果的最大采摘量。


解题思路:对每棵果树的采摘日期从小到大排序,日期靠前的先采摘。


代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
int const maxn=300005;
struct A
{
    int d,b;
}a[3005];
int cmp(A p,A q)
{
    return p.d<q.d;
}
int main()
{
    
    int n,v,ans=0;
    scanf("%d%d",&n,&v);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i].d,&a[i].b);
    }
    sort(a+1,a+n+1,cmp);
    for(int day=1;day<=maxn;day++)
    {
        int cur=0,p=0;         //cur为每天的采摘量
        for(int i=1;i<=n;i++)
        {
            if(a[i].d>day)     //如果还未到达当前果树的日期,后面果树的日期也未到达,结束当前循环
                break;
            if(a[i].d!=day&&a[i].d+1!=day)
                continue;
            if(a[i].b>0)        //在规定的两天日期可以采摘
            {
                p=1;
                if(a[i].b+cur<=v)  //a[i].b表示当前果树上果实个数,如果采摘数量会有更新
                {
                    cur+=a[i].b;
                    a[i].b=0;
                }
                else
                {
                    a[i].b-=(v-cur);
                    cur=v;
                    break;
                }
            }
        }
        ans+=cur;
        if(a[n].d+1<day)
            break;
    }
    printf("%d\n",ans);
    return 0;
} 


手把手教你配置微信商户平台IP白名单:企业付款到零钱必备步骤 本文详细解析了微信商户平台IP白名单的配置原理与实操步骤,这是实现企业付款到零钱功能的关键安全环节。文章从理解IP白名单的安全逻辑出发,指导开发者精准定位服务器公网IP,并提供了在商户平台后台的详细配置流程与常见问题排查指南,帮助开发者高效完成配置,确保企业付款API的顺利调用。 阅读详情

相关推荐

别再为Power BI瀑布图发愁了!用这个DAX公式+堆积柱状图,5分钟搞定现金流量表可视化

本文介绍了一种使用DAX公式和堆积柱状图快速实现Power BI现金流量表可视化的高效方法。通过详细的步骤和代码示例,帮助财务分析人员5分钟内完成专业级报表制作,解决传统瀑布图配置复杂、灵活性差的问题,显著提升工作效率。

weixin_28677005的博客 246

Valera and Fruits(贪心)

B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera loves his garden, where n fruit trees g...

Simone chou... 156

GNSS数据处理新手避坑:手把手教你用GAMP_GOOD下载IGS/MGEX数据(附.cfg文件详解)

本文详细介绍了如何使用GAMP_GOOD进行GNSS数据处理,从基础配置到高级参数调优,帮助新手避开常见错误。内容包括软件安装、配置文件详解、数据源选择、测站文件配置以及性能优化技巧,特别适合GNSS数据处理初学者快速上手。

weixin_30338481的博客 390

Codeforces Round #252 (Div. 2)B. Valera and Fruits

#include #include using namespace std; #define inf 0x3f3f3f3f int main() { int n,m,a,b; int s=0; int t[3111]; memset(t,0,sizeof(t)); cin>>n>>m; int maxt=0; for(int i=0;i<n;i++)

smz436487的专栏 730

新卡尝鲜记:RTX 5070Ti适配PyTorch生态的实战避坑指南

本文分享了RTX 5070Ti适配PyTorch生态的实战经验。针对CUDA 12.8兼容性问题,详细介绍了安装PyTorch Nightly版本、手动编译xformers库以及寻找PyTorch3D第三方预编译包的完整流程与解决方案,帮助用户快速搭建可用的深度学习开发环境。

weixin_29094775的博客 287

SQL实现数据仓库ETL:分层设计、增量抽取与性能优化实践

在数据仓库建设过程中,ETL(抽取、转换、加载)是数据流转的核心环节。传统观点常将ETL与专业工具或大数据框架绑定,但在中小规模数据场景下,基于SQL的ETL方案凭借低门槛、高可维护性和直观的排错体验,成为高效且务实的选择。本文从ETL的基础概念出发,阐述数据仓库分层(ODS、DWD、DWS、ADS)中每层ETL的定位与职责,重点剖析增量抽取策略(时间戳、主键、日志)下的SQL实现方式,以及数据清洗、去重和格式化的常见写法。同时,结合真实项目经验,分享慢SQL优化技巧、任务调度依赖设计、幂等性保障和常见问题

weixin_33290540的博客 345

A - Valera and Fruits

Valera and Fruits

Yuric的专栏 520

Security Onion的部署(超详细)

本文介绍了开源入侵检测系统securityonion的部署

qq_72583325的博客 6067

codeforces-Valera and Fruits

http://codeforces.com/contest/441/problem/B 题目大一

qqcyclone的专栏 661

Linux下CUDA 11.8与vllm的完美搭配:从环境配置到避坑指南

本文详细介绍了在Linux系统中为CUDA 11.8环境部署vLLM的完整实战指南。针对cu118与vLLM的版本兼容性核心问题,提供了从Python、PyTorch版本选择,到关键依赖vllm-nccl-cu11的安装避坑,以及环境调优、生产级容器化部署的全面解决方案,帮助开发者高效构建稳定的大模型推理服务。

weixin_29095049的博客 308

PyCharm配置WSL开发环境保姆级教程:从安装Conda到项目依赖一键搞定

本文提供PyCharm配置WSL开发环境的完整教程,涵盖从安装Conda到项目依赖管理的全流程。详细介绍了WSL2环境准备、Conda环境配置、PyCharm远程解释器设置等关键步骤,并包含实用技巧和常见问题解决方案,帮助开发者高效搭建Python开发环境。

weixin_42620202的博客 307

codeforces252-B - Valera and Fruits

#include #include #include #include #include #include #include #include #include #include #include #include #include #define Maxn 3005 typedef long long ll; #define rep(i,j,n) for(int i=j;i<=n;i+

Griffin_0的专栏 548

matlab RANSAC拟合圆柱【2025最新版】

RANSAC拟合圆柱

点云侠的博客 3135

Codeforces Round #252(Div. 2) 441B. Valera and Fruits 贪心

B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera loves his garden, where n fruit

Jonariguez 吾本优秀 808

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Codeforces Round #252 (Div. 2)-B. Valera and Fruits

题目: 题意:

Halo 725

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Codeforces Round #252 (Div. 2) 441B. Valera and Fruits

英语不好就是坑啊。这道题把我坑残了啊。5次WA一次被HACKA

veritaswu的专栏 1052

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Codeforces Round #252 (Div. 2) B. Valera and Fruits

Let's start counting days from 1 to 3001. Let current day be i. Additionally, we'll have cur variable — number of fruit we didn't collect previous days. Suppose now fruit is ripen current day. If no

守护生命的绿荷的专栏 415

Codeforces Round #521 (Div. 3) ABCDEF1F2总结

要是C没挂终测,我这场就。。。没有什么要是。C题读错题了。终测前6道rk47,终测完5道rk140。虽然上了86分,但是心里还是很sad。。。 A题: 没什么好说的。统计1~k的奇数和偶数个数。答案就是n*((k+1)/2)-(m*(k/2))。 B题: 考虑贪心,每次出现“101”这种情况我们就把后面的1改成0。这样10101这种情况我们只需要改一个,肯定是最优的。 C题: 这道题我...

LSD20164388的博客 442

noj 1046 第K回文数

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和图片上传 LaTex数学公式 UML序列图和流程图 离线写博客 导入导出Markdown文件 丰富的快捷键 快捷键 加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl

ysCover 1224

codeforces 538 A.Cutting Banner

A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A large banner with word CODEFORCES was o

ysCover 1127

hdu 5202 Rikka with string(模拟)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 625    Accepted Submission(s): 244 Problem Description As we know, Ri

ysCover 1058
上一篇: Codeforces Round #249 (Div. 2) B. Pasha Maximizes(模拟)
下一篇: poj 2192 Zipper(DFS+剪枝)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值