【CF Edu 28 B. Math Show】
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
input
3 4 11
1 2 3 4
output
6
input
5 5 10
1 2 4 8 16
output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
【翻译】有n个一样的套题,每套题包含k个题,每个题的解决时间ai可能不同(输入)。做一道题得到1分,做完一套题另外加一分,询问m时间内最多得到多少分。
题解:
①直接贪心写很麻烦,但是观察到对于一套题只有两种状态:做完,没做完。
②由于每套题是完全相同的,所以暴力枚举做完了的套题数,剩下的没做完就排序贪心完成。
#include<stdio.h>
#define S(x,y) (x^=y^=x^=y)
#define go(i,a,b) for(int i=a;i<=b;i++)
int n,k,a[50];long long Time,sum,Score,ans,m;
int main()
{
scanf("%d%d%d",&n,&k,&m);
go(i,1,k)scanf("%d",a+i),sum+=a[i];
go(i,1,k)go(j,i,k)if(a[i]>a[j])S(a[i],a[j]); go(i,0,n){Score=(k+1)*i;if((Time=sum*i)>m)break;
go(j,1,k)Time+(n-i)*a[j]>=m?Score+=(m-Time)/a[j],j=k:(Time+=(n-i)*a[j],Score+=n-i);
Score>ans?ans=Score:1;}printf("%I64d\n",ans);return 0;
}//Paul_Guderian
天空升起紫色的烟花,眼前是一片辉煌
我迎着风向前狂奔,这速度远不能抛开忧伤。————汪峰《十二月的泪》
【CF Edu 28 B. Math Show】的更多相关文章
- 【CF Edu 28 C. Four Segments】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF Edu 28 A. Curriculum Vitae】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【2020.11.28提高组模拟】T1染色(color)
[2020.11.28提高组模拟]T1染色(color) 题目 题目描述 给定 \(n\),你现在需要给整数 \(1\) 到 \(n\) 进行染色,使得对于所有的 \(1\leq i<j\leq ...
- 【CF Round 434 B. Which floor?】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF edu 30 D. Merge Sort】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【Cf edu 30 B. Balanced Substring】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【2020.11.28提高组模拟】T2 序列(array)
序列(array) 题目描述 给定一个长为 \(m\) 的序列 \(a\). 有一个长为 \(m\) 的序列 \(b\),需满足 \(0\leq b_i \leq n\),\(\sum_{i=1}^ ...
- 01 语言基础+高级:1-3 常用API第一部分_day08【String类、static、Arrays类、Math类】
day08[String类.static.Arrays类.Math类] String类static关键字Arrays类Math类 教学目标能够使用String类的构造方法创建字符串对象能够明确Stri ...
- B. Lost Number【CF交互题 暴力】
B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...
随机推荐
- tcp文件下载客户端+服务端
客户端: import socket if __name__ == '__main__': # 创建tcp客户端socket tcp_client_socket = socket.socket(soc ...
- dom技术解析xml下jaxp解析器详细代码
1.使用jaxp实现查询操作 person.xml <?xml version="1.0" encoding="UTF-8" standalone=&qu ...
- python 一些基础知识
Python 注释的原理: 原理:根据对象的引用计数器,对象创建会给对象一个引用计数器属性.如果该属性的值为0,那么该对象会被释放.创建一个字符串对象,但是没有任何引用,计数器为0. Python小整 ...
- 17-比赛1 F - 较小元素 Weak in the Middle (set)
Seg-El has last chance to make the final changes in order to prevent the destruction of Krypton. He ...
- python向多个邮箱发邮件--注意接收是垃圾邮件
群发邮件注意:三处标红的地方 # -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText from emai ...
- python Beautiful Soup库入门
bs4库的HTML内容遍历方法 基于bs4库的HTML格式输出 显示:友好的显示 <tag>.prettify() 编码:bs4库将任何HTML输入都变成utf-8编码(python 3. ...
- Nginx 高级配置
nginx官方网站:http://nginx.org/ 1. Nginx连接后端的方式:反向代理(proxy_pass).直连fastcgi(fastcgi_pass) 例子: fastcgi_pa ...
- python os模块练习题
# 1.获取某个文件所在目录的上一级目录. # 例如'D:\python\projects\test19.py'目录的结果 :D:\python\projects # 方法1 # path = os. ...
- 十三、MySQL之IDE工具介绍及数据备份
一.IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 二.MySQL数据备份 # ...
- Android getLocationInWindow
参考博客: http://blog.sina.com.cn/s/blog_44d19b500102vpve.html 这篇博客,我看了三遍,终于看懂了.恩,我就喜欢这样不放弃的自己. 1.getLoc ...