A. Alyona and Numbers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.

Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and equals 0.

As usual, Alyona has some troubles and asks you to help.

Input

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).

Output

Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.

Examples
Input
6 12
Output
14
Input
11 14
Output
31
Input
1 5
Output
1
Input
3 8
Output
5
Input
5 7
Output
7
Input
21 21
Output
88
Note

Following pairs are suitable in the first sample case:

for x = 1 fits y equal to 4 or 9;

  • for x = 2 fits y equal to 3 or 8;
  • for x = 3 fits y equal to 2, 7 or 12;
  • for x = 4 fits y equal to 1, 6 or 11;
  • for x = 5 fits y equal to 5 or 10;
  • for x = 6 fits y equal to 4 or 9.

Only the pair (1, 4) is suitable in the third sample case.

题意:给你 n,m     1 ≤ x ≤ n, 1 ≤ y ≤ m  问有多少对x/y 使得(x+y)%5==0

题解:水

 #include <bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m;
int main()
{
scanf("%d %d",&n,&m);
ll ans=;
for(int i=;i<=n;i++)
{
int exm=i%;
int re=-exm;
if(m>=re){
ans=ans+(m-re)/;
ans++;
}
}
cout<<ans<<endl;
return ;
}
B. Alyona and Mex
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.

Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.

Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.

The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Output

Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.

Examples
Input
5
1 3 3 3 6
Output
5
Input
2
2 1
Output
3
Note

In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.

To reach the answer to the second sample case one must not decrease any of the array elements.

题意:给你n个数 每次操作只能减小某个数 经过一系列操作之后 使得没有出现的数的最小值尽量大

题解:水

 #include <bits/stdc++.h>
#define ll __int64
using namespace std;
int n;
int a[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n);
int now=;
for(int i=;i<=n;i++)
{
if(now<=a[i])
now++;
else
continue;
}
cout<<now<<endl;
return ;
}
C. Alyona and the Tree
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.

The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex v sad if there is a vertex u in subtree of vertex v such that dist(v, u) > au, where au is the number written on vertex u, dist(v, u) is the sum of the numbers written on the edges on the path from v to u.

Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root.

Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove?

Input

In the first line of the input integer n (1 ≤ n ≤ 105) is given — the number of vertices in the tree.

In the second line the sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 109) is given, where ai is the number written on vertex i.

The next n - 1 lines describe tree edges: ith of them consists of two integers pi and ci (1 ≤ pi ≤ n,  - 109 ≤ ci ≤ 109), meaning that there is an edge connecting vertices i + 1 and pi with number ci written on it.

Output

Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree.

Example
Input
9
88 22 83 14 95 91 98 53 11
3 24
7 -8
1 67
1 64
9 65
5 12
6 -80
3 8
Output
5
Note

The following image represents possible process of removing leaves from the tree:

题意:给你一个树 有点权 边权 删除最少的叶子结点 使得 对于任意一个点到其子树中的点的路径边权和小于等与目标点的点权

题解:dfs处理 记录当前节点的祖先节点中到当前节点的路径边权和的最大值

 #include <bits/stdc++.h>
#define ll __int64
using namespace std;
ll n;
ll a[];
ll p[];
ll in[];
ll out[];
ll d[];
map<ll,ll> mp;
ll nedge=;
ll dfn=;
ll re=;
struct node
{
ll to;
ll pre;
ll we;
}N[];
void add(ll pre,ll to,ll we)
{
nedge++;
N[nedge].to=to;
N[nedge].we=we;
N[nedge].pre=p[pre];
p[pre]=nedge;
}
void getdfs(ll root,ll sum,ll now)
{
in[root]=++dfn;
d[root]=max(sum,now);
sum=d[root];
mp[root]=;
for(int i=p[root];i;i=N[i].pre){
if(mp[N[i].to])
continue;
getdfs(N[i].to,sum+N[i].we,N[i].we);
}
out[root]=dfn;
}
void dfs(ll root)
{
mp[root]=;
for(int i=p[root];i;i=N[i].pre){
if(mp[N[i].to])
continue;
if(d[N[i].to]>a[N[i].to])
{
re=re+out[N[i].to]-in[N[i].to]+;
continue ;
}
dfs(N[i].to);
}
}
int main()
{
ll r,w;
memset(p,,sizeof(p));
scanf("%I64d",&n);
for(ll i=;i<=n;i++)
scanf("%I64d",&a[i]);
for(ll i=;i<=n;i++)
{
scanf("%I64d %I64d",&r,&w);
add(i,r,w);
add(r,i,w);
}
getdfs(,0ll,0ll);
mp.clear();
dfs();
printf("%I64d\n",re);
return ;
}

Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp的更多相关文章

  1. Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题

    A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...

  2. Codeforces Round #358 (Div. 2) C. Alyona and the Tree dfs

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. 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 ...

  4. Codeforces Round #381 (Div. 2) D. Alyona and a tree dfs序+树状数组

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

  5. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  6. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  7. Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化

    E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given ...

  8. Codeforces Round #358 (Div. 2) D. Alyona and Strings dp

    D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...

  9. Codeforces Round #358 (Div. 2) C. Alyona and the Tree 水题

    C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona deci ...

  10. Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题

    B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...

随机推荐

  1. C语言—单链表

    单链表操作:读取,插入和删除 #include "stdafx.h" #include <string.h> #include <stdio.h> #inc ...

  2. 单源最短路——Bellman-Ford算法

    1.Dijkstra的局限性 Dijkstra算法是处理单源最短路径的有效算法,但它局限于边的权值非负的情况,若图中出现权值为负的边,Dijkstra算法就会失效,求出的最短路径就可能是错的. 列如以 ...

  3. Java中的多态,引用类型的转换

    1.多态分为引用多态和方法多态,见测试类 package com.wangcf; //父类 public class Animal { public void eat(){ System.out.pr ...

  4. DS06--图

    一.学习总结 1.图的思维导图 2.图学习体会 深度优先遍历与广度优先遍历 不同点:广度优先搜索,适用于所有情况下的搜索,但是深度优先搜索不一定能适用于所有情况下的搜索.因为由于一个有解的问题树可能含 ...

  5. haproxy入门 (作用: 高可用性,负载平衡和用于TCP和基于http的应用程序的代理)

    安装haproxy 1:RPM包安装 yum install -y haproxy   2:编译安装 http://www.haproxy.org/#down   例如安装1.7.9版本 http:/ ...

  6. 3dContactPointAnnotationTool开发日志(三二)

      今天就是看怎么把论文的python源码预测出来的smpl模型的姿势和形状参数弄到unity版本的smpl里,但是python版本的和unity版本的不一样.   先看看他的fit_3d.py:   ...

  7. js登录界面代码自用

    var btn = document.getElementById("a4"); var usne = document.getElementById("username ...

  8. 【BioCode】读文件夹以发现缺失文件

    代码说明: 使用单个蛋白质的txt计算PSSM生成的结果为单个的PSSM文件. 但是由于一些原因(如蛋白质序列过长),会导致一些蛋白质txt文件无法计算出pssm,为了找到这些没有计算出pssm的蛋白 ...

  9. HDU 2105 The Center of Gravity

    http://acm.hdu.edu.cn/showproblem.php?pid=2105 Problem Description Everyone know the story that how ...

  10. php PDO操作类

    <?php /*//pdo连接信息 $pdo=array("mysql:host=localhost;dbname=demo;charset=utf8","root ...