Codeforces Round #381 (Div. 2) A B C

A:

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 arubles, 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 3 4
output
3
input
6 2 1 1
output
1
input
4 4 4 4
output
0
input
999999999 1000000000 1000000000 1000000000
output
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.

这题其实可以直接上暴力的。。。还去分类讨论了。。而且速度还那么慢。。。而且居然还漏了一种情况

智障啊。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;
int main(){
    long long n,a,b,c,now;
    scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
    if(n==0){
        now = min(4*a,2*b);
        now = min(now,4*c);
        now = min(now,2*a+b);
        now = min(now,a+c);
        now = min(now,b+2*c);
        printf("%I64d\n",now);
        return 0;
    }
    if(n%4==1){
        now  = min(a*3,c);
        now = min(now,a+b);
        printf("%I64d\n",now);
    }else if(n%4==2){
        now = min(a*2,b);
        now = min(now,2*c);
        printf("%I64d\n",now);
    }else if(n%4==3){
        now = min(a,3*c);
        now = min(now,b+c);
        printf("%I64d\n",now);
    }else{
        printf("0\n");
    }
    return 0;
}

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
5 4
1 -2 1 3 -4
1 2
4 5
3 4
1 4
output
7
input
4 3
1 2 3 4
1 3
2 4
1 1
output
16
input
2 2
-1 -2
1 1
1 2
output
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.




至今没有明白这个故事在说啥。。。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 110;
int a[maxn];
int main(){
    int n,m,i,j,l,r;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int ans = 0,now = 0;
    for(i=1;i<=m;i++){
        scanf("%d%d",&l,&r);
        now = 0;
        for(j=l;j<=r;j++){
            now += a[j];
        }
        if(now>0){
            ans += now;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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
5 3
1 3
2 5
4 5
output
2
1 0 2 1 0
input
4 2
1 4
2 4
output
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.




鸟神给了提示才做的。。。。自己好智障啊。。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 1e5;
int res[maxn];
int main(){
    int n,m,i,j,l,r;
    scanf("%d%d",&n,&m);
    int minn = 1000100;
    int l0,r0;
    for(i=1;i<=m;i++){
        scanf("%d%d",&l,&r);
        if(r-l+1<minn){
            minn = r-l+1;
            l0 = l;
            r0 = r;
        }
    }
    printf("%d\n",minn);
    int len = minn-1;
    for(i=l0;i<=r0;i++){
        res[i] = len--;
    }
    len = 0;
    for(i=l0-1;i>=1;i--){
        res[i] = len;
        len = (len+1+minn)%minn;
    }
    len = minn-1;
    for(i=r0+1;i<=n;i++){
        res[i] = len;
        len = (len-1+minn)%minn;
    }
    for(i=1;i<=n;i++){
        printf("%d ",res[i]);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值