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

AFSim编译一:windows AFSim在windows上的编译 阅读详情

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;
} 


[SoC]SoC验证中bootcode与firmware相关验证经验总结 本文总结了SoC验证中bootcode和firmware的验证经验。重点介绍了两种数据加载方法:1)使用Verilog系统函数$readmemh/$readmemb直接写入ROM/ARAM,需注意文件路径、格式和斜杠方向;2)通过Memory Hierarchy在initial块中操作,需要添加适当延时并注意路径拼接。文章还提供了在testcase phase中先读取数据到HASH再写入SRAM的示例,并强调加载后需使能edc_bypass以避免ECC错误。验证过程中需特别注意文件位置、格式要求及路径处理等 阅读详情

相关推荐

告别手动群发!用IDA Pro和CE搞定企业微信4.1.38.6011的HOOK开发(附完整代码)

本文详细介绍了如何利用IDA Pro和Cheat Engine进行企业微信4.1.38.6011的HOOK开发,实现自动化群发功能。从逆向工程环境配置、关键函数定位到HOOK框架设计,提供完整代码示例,帮助企业提升运营效率。

weixin_42533120的博客 485

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

OpenClaw实操:给网站装上“智能眼睛”?手把手教你用OpenClaw实时监控网站

本文介绍如何在Windows系统使用OpenClaw构建智能网站监控助手。手把手教你通过配置本地AI模型,让openclaw构建的ai助手自动检测指定网页的内容变化,理解更新重要性,并及时通过邮件、微信、Telegram等渠道发出预警,让你第一时间掌握关键信息,彻底告别手动刷新。

plawuyue的博客 2167

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的专栏 731

同济大学824复试全攻略:从笔试到面试的实战解析

本文详细解析同济大学824复试全流程,包括专业课笔试、外语听力与口语、专业外语笔试和专业综合面试的备考策略。重点分享数字信号处理、计算机网络等专业课的高效学习方法,以及专业外语速成和口语面试技巧,助力考生全面提升复试表现。

qq_27496129的博客 1065

新手小白入门编程第2讲 JAVA编程环境搭建 JDK与环境变量、Eclipse

1 JDK 1.1 JDK概述 JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。 JDK是整个java开发的核心,它包含了: JAVA开发工具(jdk\bin) 基础开发库(jdk\jre\lib\rt.jar) 基础开发库的源码(jdk\src.zip) 1.2 JDK下载与安装 本次使用的是JDK1.8,详细安装步骤可以参见”JDK培优安装手册”. 注意事项: 同时安装多个JDK时需要使用执行环境变量来确认使用的是哪个jdk 安装时选择默认选项安装到默认

程序媛泡泡的博客 4万+

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

湿敏电阻HR202的两种驱动方案实测:IO充放电法 vs. 交流方波ADC法,哪个更适合你?

本文深入评测湿敏电阻HR202的两种驱动方案:IO充放电法和交流方波ADC法。通过原理图分析、精度实测和资源占用对比,揭示交流方波ADC法在精度和稳定性上的优势,特别适合长期监测场景。同时提供IO充放电法在资源受限情况下的应用建议,帮助工程师根据项目需求做出最优选择。

weixin_30421809的博客 471

A - Valera and Fruits

Valera and Fruits

Yuric的专栏 521

特征提取 Features Extraction

介绍了特征提取的基本概念,从分类变量,文本信息和图片信息中进行特征提取的方法,以及实现特征提取的类库

JasonH2021的博客 1万+

10种电阻综合对比——《器件手册--电阻》

可变电阻在电子设备中也有很多用途,如在收音机的音量调节电路中,通过旋转可变电阻的旋钮来改变电路中的电阻值,从而改变通过扬声器的电流,实现音量的调节。根据电阻定律,电阻R = ρ(L/S),其中ρ是导体材料的电阻率,L是导体的长度,S是导体的横截面积。比如,同样材料制成的两根电线,粗的电线电阻比细的电线电阻小,长的电线电阻比短的电线电阻大。电流采样电阻的工作原理基于欧姆定律,即电阻两端的电压与通过电阻的电流成正比,公式为 I = V/R,其中 I是电流,V是电阻两端的电压,R 是电阻值。

XU157303764的博客 3153

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

Unity零基础到进阶 | Unity中的内存泄漏全解析,原因、排查及避免

Unity 内存泄漏并非传统C++语境中的野指针或未释放堆内存,而是基于其「托管内存(C#)+ 原生内存(引擎/非托管)」双架构的特殊问题——即已废弃、不再被业务逻辑使用的内存块,无法被引擎或系统自动回收,持续占用内存空间,最终引发内存暴涨、GC卡顿、OOM(内存溢出)崩溃,其中移动端、主机端受影响最显著。 Unity 内存主要分为三类,其中泄漏仅发生在前两类,栈内存因系统自动分配/释放,无泄漏风险:

努力前行,总会成为自己心中的那道光 1万+

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 吾本优秀 810

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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

题目: 题意:

Halo 725

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

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

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

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

veritaswu的专栏 1053

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-Valera and Fruits

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

qqcyclone的专栏 663

noj 1046 第K回文数

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

ysCover 1225

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 1132

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、付费专栏及课程。

余额充值