Problem Statement

Takahashi will toss a coin $N$ times.
He also has a counter, which initially shows $0$.

Depending on the result of the $i$-th coin toss, the following happens:

  • If it heads: Takahashi increases the counter's value by $1$ and receives $X_i$ yen (Japanese currency).
  • If it tails: he resets the counter's value to $0$, without receiving money.

Additionally, there are $M$ kinds of streak bonuses. The $i$-th kind of streak bonus awards $Y_i$ yen each time the counter shows $C_i$.

Find the maximum amount of money that Takahashi can receive.

Constraints

  • $1\leq M\leq N\leq 5000$
  • $1\leq X_i\leq 10^9$
  • $1\leq C_i\leq N$
  • $1\leq Y_i\leq 10^9$
  • $C_1,C_2,\ldots,C_M$ are all different.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$

\(X_1\) \(X_2\) \(\ldots\) \(X_N\)

\(C_1\) \(Y_1\)

\(C_2\) \(Y_2\)

\(\vdots\)

\(C_M\) \(Y_M\)

Output

Print the maximum amount of money that Takahashi can receive, as an integer.


Sample Input 1

6 3
2 7 1 8 2 8
2 10
3 1
5 5

Sample Output 1

48

If he gets head, head, tail, head, head, head, in this order, the following amounts of money are awarded.

  • In the $1$-st coin toss, the coin heads. Change the counter's value from $0$ to $1$ and receive $2$ yen.
  • In the $2$-nd coin toss, the coin heads. Change the counter's value from $1$ to $2$ and receive $7$ yen. Additionally, get $10$ yen as a streak bonus.
  • In the $3$-rd coin toss, the coin tails. Change the counter's value from $2$ to $0$.
  • In the $4$-th coin toss, the coin heads. Change the counter's value from $0$ to $1$ and receive $8$ yen.
  • In the $5$-th coin toss, the coin heads. Change the counter's value from $1$ to $2$ and receive $2$ yen. Additionally, get $10$ yen as a streak bonus.
  • In the $6$-th coin toss, the coin heads. Change the counter's value from $2$ to $3$ and receive $8$ yen. Additionally, get $1$ yen as a streak bonus.

In this case, Takahashi receives $2+(7+10)+0+8+(2+10)+(8+1)=48$ yen in total, which is the maximum possible.

Note that streak bonuses are awarded any number of times each time the counter shows $C_i$.

As a side note, if he gets head in all $6$ coin tosses, he only receives $2+(7+10)+(1+1)+8+(2+5)+8=44$ yen, which is not the maximum.


Sample Input 2

3 2
1000000000 1000000000 1000000000
1 1000000000
3 1000000000

定义\(dp_{i,j}\)为扔了 \(i\) 次硬币 counter 为 \(j\) 的最大收钱数。

设 counter 达到 \(k\) 时收到 \(t_k\) 日元。

如果 \(j\ne 0\),那么 \(dp_{i,j}=dp_{i-1,j-1}+X_i+t_j\)

如果 \(j=0\) 为 0,\(dp_{i,j}=\max\limits_{j=0}^{n-1}dp_{i-1,j}\)

#include<bits/stdc++.h>
using namespace std;
const int N=5005;
int x[N],c,y,t[N],n,m;
long long dp[N][N],ans;
int main()
{
memset(dp,-0x7f,sizeof(dp));
dp[0][0]=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",x+i);
for(int i=1;i<=m;i++)
scanf("%d%d",&c,&y),t[c]+=y;
for(int i=1;i<=n;i++)
{
dp[i][0]=dp[i-1][0];
for(int j=1;j<=n;j++)
dp[i][j]=dp[i-1][j-1]+t[j]+x[i],dp[i][0]=max(dp[i][0],dp[i-1][j-1]),ans=max(ans,dp[i][j]);
}
printf("%lld",ans);
}

[ABC261D] Flipping and Bonus的更多相关文章

  1. Flipping elements with WPF

    http://yichuanshen.de/blog/2010/11/13/flipping-elements-with-wpf/ Have you already seen ForgottenTim ...

  2. ZOJ3762 The Bonus Salary!(最小费用最大流)

    题意:给你N个的任务一定要在每天的[Li,Ri]时段完成,然后你只有K天的时间,每个任务有个val,然后求K天里能够获得的最大bonus. 思路:拿到手第一直觉是最小费用最大流,然后不会建图,就跑去想 ...

  3. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  4. 【OpenMesh】Some basic operations: Flipping and collapsing edges

    这一节中你将学到一些OpenMesh中早已提供的基础操作. 内容包括三角形网格边的翻转以及通过连接邻接的顶点边缘折叠. 三角形网格的翻转(Flipping edges) 考虑到两个邻接面的三角形网格中 ...

  5. Flipping Game(枚举)

    Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #191 (Div. 2)---A. Flipping Game

    Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. veridata实验举例(2)验证表BONUS与表SALGRADE两节点同步情况

    veridata实验举例(2)验证表BONUS与表SALGRADE两节点同步情况 续接前几篇文章: 1.GoldenGate配置(一)之单向复制配置 地址:点击打开链接 2.GoldenGate配置( ...

  8. Flipping Parentheses~Gym 100803G

    Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of t ...

  9. [LeetCode] Flipping an Image 翻转图像

    Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...

  10. [SQL]LeetCode577.员工奖金 | Employee Bonus

    Select all employee's name and bonus whose bonus is < 1000. Table:Employee +-------+--------+---- ...

随机推荐

  1. 角度新奇!第一次看到这样使用MyBatis的,看得我一愣一愣的。

    你好呀,我是歪歪. 这期给大家分享一个读者给我分享的一个关于 MyBatis 的"编程小技巧",说真的,这骚操作,直接把我看得一愣一愣的. 我更情愿叫它:坑你没商量之埋雷大法. D ...

  2. 【JMeter】使用BeanShell写入内容到文件

    使用BeanShell写入内容到文件 目录 使用BeanShell写入内容到文件 一.前言 二.提取 三.写入 一.前言 ​ 在我们日常工作中,可能会遇到需要将请求返回的数据写入到文件中.在我们使用J ...

  3. Leetcode刷题笔记——单调性

    单调性 单调性是数学中使用的一种常见性质,通常用于描述函数,在高等数学中的定义常常为: 设函数f(x)在区间I上有定义,如果对于I上的任意两个数x1和x2,当x1<x2时,有f(x1)<f ...

  4. Mysql高级11-后台进程

    一.前言 MySQL的服务实现通过后台多个线程.内存池.文件交互来实现对外服务的,不同线程实现不同的资源操作,各个线程相互协助,共同来完成数据库的服务.MySQL常用的后台线程概括如下,分为Maste ...

  5. Solution -「洛谷 P2000」拯救世界

    Description Link. 概括什么好麻烦哦 w. Solution 生成函数裸题. 把所有情况罗列出来: kkk: 金: \(1+x^6+x^{12}+\dots=\frac{1}{1-x^ ...

  6. 在线问诊 Python、FastAPI、Neo4j — 创建 节点关系

    目录 关系:症状-检查 关系:疾病-症状 代码重构 relationship_data.csv 症状,检查,疾病,药品,宜吃,忌吃 "上下楼梯疼,不能久站,感觉有点肿"," ...

  7. 卷积导向快速傅里叶变换(FFT/NTT)教程

    1 Forewords 卷积,但不止卷积 - FFT 漫谈 先有 FT,再有 DFT,才有 FFT 时频转换是最初的用途 发现单位根优秀性质,James Cooley, John Tukey 发明现代 ...

  8. c语言代码练习7

    //输出0-100的三倍数字#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main() { int i = 0; int ...

  9. PostgreSQL学习笔记-3.基础知识:CROSS、INNER、LEFT OUTER、RIGHT OUTER、FULL OUTER、UNION

    PostgreSQL JOIN 子句用于把来自两个或多个表的行结合起来,基于这些表之间的共同字段. 在 PostgreSQL 中,JOIN 有五种连接类型: CROSS JOIN :交叉连接INNER ...

  10. Android应用中对于微信分享的实例及问题

    源码地址 如何分享 分享无相应 分享结果如何接收响应 微信 分享回调 (提示几点关键问题:   debug_key 一定要获得对应的签名码 然后和weixin官网的appid对应     ) 几点注意 ...