此题需要注意的两个地方是

(1)在某天生产出来的Slimonades,必须在stale_limit天内必须卖完,否则超过stale_limit内抛弃(东西都有保质期)

(2)每天生产出来的Slimonades的数量在0到morning[i]之间,而不是morning[i]

故第i天卖的东西可能来自max(0,i-stale_limit+1)~i 之间任何一天的东西,假设j在这些天数之间,

则第j天生产的东西在第i天卖的数量为min(morning[j], customer[i]),故遍历一遍即可

#include <iostream>
#include <vector>
#include <algorithm> using namespace std; class SlimeXSlimonadeTycoon{
public:
int sell(vector<int> morning, vector<int> customers, int stale_limit){
int res = ;
for(int i = ; i < morning.size(); ++ i){
for(int j = max(,i-stale_limit+); j<= i; ++ j){
if(customers[i] > ){
int t = min(customers[i],morning[j]);
res += t;
customers[i] -=t;
morning[j] -=t;
}
}
}
return res;
}
};

topcoder SRM 617 DIV2 SlimeXSlimonadeTycoon的更多相关文章

  1. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  2. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  3. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  4. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

  5. topcoder SRM 628 DIV2 BracketExpressions

    先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...

  6. topcoder SRM 628 DIV2 BishopMove

    题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...

  7. Topcoder SRM 683 Div2 B

    贪心的题,从左向右推过去即可 #include <vector> #include <list> #include <map> #include <set&g ...

  8. Topcoder SRM 683 Div2 - C

    树形Dp的题,根据题意建树. DP[i][0] 表示以i为根节点的树的包含i的时候的所有状态点数的总和 Dp[i][1] 表示包含i结点的状态数目 对于一个子节点v Dp[i][0] = (Dp[v] ...

  9. Topcoder SRM 626 DIV2 SumOfPower

    本题就是求所有连续子数列的和 开始拿到题目还以为求的时数列子集的和,认真看到题目才知道是连续子数列 循环遍历即可 int findSum(vector <int> array) { ; ; ...

随机推荐

  1. Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- AIDL

    服务端: 最终项目结构: 这个项目中,我们将用到自定义类CustomData作为服务端与客户端传递的数据. Step 1:创建CustomData类 package com.ldb.android.e ...

  2. EasyUi – 5.修改$.messager.show() 弹出窗口在浏览器顶部中间出现

    由于在easyui中$.messager.show() 只有一种弹出方式(在浏览器的或下角弹出),我最近在做一个项目的时候需要在浏览器的顶部中间出现.由于自己写花那么多的时间,所以就去修改了原码(不推 ...

  3. php提示 Notice: Use of undefined constant name - assumed

    我们知道php在数组中写变量有二几种方法,我们出现这种提示就是你写成了[name]这种所以会有Notice: Use of undefined constant name - assumed name ...

  4. ASP.NET MVC 伪静态的实现

    public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.Ignore ...

  5. x86架构的android手机兼容性问题

    x86架构的android手机兼容性问题 http://www.cnblogs.com/guoxiaoqian/p/3984934.html 自从CES2012上Intel发布了针对移动市场的Medf ...

  6. Pyqt清空Win回收站

    Pyqt清空回收站其实的调用Python的第三方库,通过第三方库调用windows的api删除回收站的数据 一. 准备工作 先下载第三方库winshell 下载地址: https://github.c ...

  7. MDX语法之排序函数Order

    使用场景: 排列指定集的成员,可以选择保留或打乱原有的层次结构. 语法: Numeric expression syntax Order(Set_Expression, Numeric_Express ...

  8. POJ 2299 Ultra-QuickSort 逆序数 树状数组 归并排序 线段树

    题目链接:http://poj.org/problem?id=2299 求逆序数的经典题,求逆序数可用树状数组,归并排序,线段树求解,本文给出树状数组,归并排序,线段树的解法. 归并排序: #incl ...

  9. JS判断输入值是否为正整数

    JS中的test是原来是JS中检测字符串中是否存在的一种模式,JS输入值是否为判断正整数代码: <script type=”text/javascript”> function test( ...

  10. 几个国内速度最快的centos yum(更新源)

    转自:http://blog.itpub.net/15711267/viewspace-1068862/ 中国科技大学源 cd /etc/yum.repos.d mv CentOS-Base.repo ...