A. Alyona and copybooks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.

What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.

Input

The only line contains 4 integers nabc (1 ≤ n, a, b, c ≤ 109).

Output

Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.

Examples
input
  1. 1 1 3 4
output
  1. 3
input
  1. 6 2 1 1
output
  1. 1
input
  1. 4 4 4 4
output
  1. 0
input
  1. 999999999 1000000000 1000000000 1000000000
output
  1. 1000000000
Note

In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.

In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.

In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.

In the fourth example Alyona should buy one pack of one copybook.

题意:1件的费用为a  2件的费用为b  3件的费用为c  现在已经拥有n件物品  购买另外k件 使得(n+k)%4==0 输出最小的花费

题解;水 共有9种策略

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #define ll __int64
  5. #define mod 10000000007
  6. using namespace std;
  7. ll n,a,b,c;
  8. int main()
  9. {
  10. scanf("%I64d %I64d %I64d %I64d",&n,&a,&b,&c);
  11. if(n%==)
  12. {
  13. printf("0\n");
  14. }
  15. else
  16. {
  17. int exm=-n%;
  18. if(exm==)
  19. {
  20. printf("%I64d\n",min(a,min(b+c,*c)));
  21. }
  22. if(exm==)
  23. {
  24. printf("%I64d\n",min(*a,min(b,c*)));
  25. }
  26. if(exm==)
  27. {
  28. printf("%I64d\n",min(*a,min(b+a,c)));
  29. }
  30. }
  31. return ;
  32. }
B. Alyona and flowers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative.

Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.

For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,  - 2, 1, 3,  - 4. Suppose the mother suggested subarrays (1,  - 2), (3,  - 4), (1, 3), (1,  - 2, 1, 3). Then if the girl chooses the third and the fourth subarrays then:

  • the first flower adds 1·1 = 1 to the girl's happiness, because he is in one of chosen subarrays,
  • the second flower adds ( - 2)·1 =  - 2, because he is in one of chosen subarrays,
  • the third flower adds 1·2 = 2, because he is in two of chosen subarrays,
  • the fourth flower adds 3·2 = 6, because he is in two of chosen subarrays,
  • the fifth flower adds ( - 4)·0 = 0, because he is in no chosen subarrays.

Thus, in total 1 + ( - 2) + 2 + 6 + 0 = 7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!

Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother.

The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100).

The next m lines contain the description of the subarrays suggested by the mother. The i-th of these lines contain two integers li and ri(1 ≤ li ≤ ri ≤ n) denoting the subarray a[li], a[li + 1], ..., a[ri].

Each subarray can encounter more than once.

Output

Print single integer — the maximum possible value added to the Alyona's happiness.

Examples
input
  1. 5 4
    1 -2 1 3 -4
    1 2
    4 5
    3 4
    1 4
output
  1. 7
input
  1. 4 3
    1 2 3 4
    1 3
    2 4
    1 1
output
  1. 16
input
  1. 2 2
    -1 -2
    1 1
    1 2
output
  1. 0
Note

The first example is the situation described in the statements.

In the second example Alyona should choose all subarrays.

The third example has answer 0 because Alyona can choose none of the subarrays.

题意:给你n个数 m个区间  在这m个区间中取若干个区间  对于选择的区间求和累加 输出最大值

题解:水 对于某个区间 若区间和大于0则累加否则舍弃

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<algorithm>
  5. #define ll __int64
  6. #define mod 10000000007
  7. using namespace std;
  8. int n,m;
  9. int a[];
  10. int sum[];
  11. int b[];
  12. int l,r;
  13. int main()
  14. {
  15. scanf("%d %d",&n,&m);
  16. sum[]=;
  17. for(int i=;i<=n;i++)
  18. {
  19. scanf("%d",&a[i]);
  20. sum[i]=sum[i-]+a[i];
  21. }
  22. for(int i=;i<=m;i++)
  23. {
  24. scanf("%d %d",&l,&r);
  25. b[i]=sum[r]-sum[l-];
  26. }
  27. sort(b+,b++m);
  28. int ans=;
  29. for(int i=m;i>=;i--)
  30. ans=ans+max(,b[i]);
  31. printf("%d\n",ans);
  32. return ;
  33. }
C. Alyona and mex
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.

Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].

Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.

You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.

The mex of a set S is a minimum possible non-negative integer that is not in S.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105).

The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri(1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri].

Output

In the first line print single integer — the maximum possible minimum mex.

In the second line print n integers — the array a. All the elements in a should be between 0 and 109.

It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.

If there are multiple solutions, print any of them.

Examples
input
  1. 5 3
    1 3
    2 5
    4 5
output
  1. 2
    1 0 2 1 0
input
  1. 4 2
    1 4
    2 4
output
  1. 3
    5 2 0 1
Note

The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5)is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.

题意:要求你构造一个长度为n的数列  给你m个区间  某个区间的mex值=当前区间内没有出现过的最小的非负数  要求构造的数列中 区间mex的最小值尽可能大

题解:找到给定区间的最小长度 len   构造一个 0 1 2...len-1 0 1 2...len-1...的数列 满足题目要求  并且mex值的最小值为len

为说明问题 对于题目的样例一

  1. 5 3
    1 3
    2 5
    4 5
    得出的结果为
    0 1 0 1 0
    试验证
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<algorithm>
  5. #define ll __int64
  6. #define mod 10000000007
  7. using namespace std;
  8. int n,m;
  9. int ans[];
  10. int l[],r[];
  11. int main()
  12. {
  13. scanf("%d %d",&n,&m);
  14. int exm=;
  15. for(int i=;i<=m;i++)
  16. {
  17. scanf("%d %d",&l[i],&r[i]);
  18. exm=min(exm,r[i]-l[i]);
  19. }
  20. for(int i=;i<=n;i++)
  21. ans[i]=;
  22. for(int i=;i<=n;i++)
  23. {
  24. for(int j=;j<=exm;j++)
  25. {
  26. if(i+j<=n)
  27. {
  28. ans[i+j]=j;
  29. }
  30. }
  31. i=i+exm;
  32. }
  33. printf("%d\n",exm+);
  34. for(int i=;i<=n;i++)
  35. printf("%d ",ans[i]);
  36. printf("\n");
  37. return ;
  38. }

Codeforces Round #381 (Div. 2) A B C 水 构造的更多相关文章

  1. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  4. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  5. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  6. Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  7. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

  8. Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想

    题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...

  9. Codeforces Round #381 (Div. 2) D dfs序+树状数组

    D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. linux 安装python-setuptools

    > wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py > python ez_setup.py --ins ...

  2. PHPExcel读取Excel文件的实现代码

    <?php require_once 'PHPExcel.php'; /**对excel里的日期进行格式转化*/ function GetData($val){ $jd = GregorianT ...

  3. JS中的数据类型检测

    JavaScript的数据类型分为两类:原始类型(primitive type)和对象类型(object type).原始类型有5种,分别是:数字(Number).字符串(String).布尔值(Bo ...

  4. Newtonsoft.Json 序列化和反序列化 时间格式

    From : http://www.cnblogs.com/litian/p/3870975.html 1.JSON序列化 string JsonStr= JsonConvert.SerializeO ...

  5. 解决Inno Setup制作中文安装包在非中文系统上显示乱码的问题

    尼玛,好几个月没更新了.囧... 目前我司新的客户端开发已经接近尾声,该改的bug已经改完,该重构的地方也都差不多了.视觉效果也已经根据美工的样式改完了.所以,就差制作安装包了.正所谓万事俱备,只欠东 ...

  6. zepto.js学习

    除了$( Zepto)对象上的直接方法外(如$.extend),文档对象中的所有方法都是集合方法. $.grep v1.0+ $.grep(items, function(item){ ... }) ...

  7. 使用共享网卡的NAT模式配置VMware中的CentOS的上网功能

    昨天写了一篇文章总结了前两天折腾VMware 10中的CentOS上网的问题,结果留下一下小瑕疵,就是视频教程中通过共享网卡使用NAT模式配置虚拟机的方法.今天在结合昨天的基础上终于弄明白了这个问题. ...

  8. DTD指定了游戏规则。

    1.DTD的作用 DTD是XML的型,列出了XML中的元素有哪些.元素间的关系.元素可以有哪些内容,元素的属性也有哪些.DTD实质说明的是元素间的关系,也就是类之间的关系.是一棵树状结构的说明,与XM ...

  9. Spring中的自动装配

    src\dayday\Person.java package dayday;/** * Created by I am master on 2016/11/28. */public class Per ...

  10. 六大免费网站数据采集器对比(火车头,海纳,云采集,ET,三人行,狂人采集)

    2013年02月27日 PHP开源系统 暂无评论 阅读 497 views 次 在目前的站长圈内,比较流行的采集工具有很多,但是总结起来,比较出名的免费的就这么几个:火车头,海纳,云采集,ET,三人行 ...