A. Anastasia and pebbles
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.

She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.

Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.

Input

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.

The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.

Output

The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.

Examples
Input
3 2
2 3 4
Output
3
Input
5 4
3 1 8 9 7
Output
5
Note

In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.

Optimal sequence of actions in the second sample case:

  • In the first day Anastasia collects 8 pebbles of the third type.
  • In the second day she collects 8 pebbles of the fourth type.
  • In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.
  • In the fourth day she collects 7 pebbles of the fifth type.
  • In the fifth day she collects 1 pebble of the second type.

题意:n个东西 每次有两个容量为k的容器 给你n个东西的大小  问你需要装几次可以装走所有的物品  每次同一个容器中只能放置一种东西

题解:水

 #include<bits/stdc++.h>
using namespace std;
int n,k;
int exm;
int main()
{
scanf("%d %d",&n,&k);
int ans=;
for(int i=;i<=n;i++)
{
scanf("%d",&exm);
ans=ans+exm/k;
if(exm%k)
ans++;
}
int re=;
re=ans/;
if(ans%)
re++;
printf("%d\n",re);
return ;
}
B. Masha and geometric depression
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.

You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.

Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.

But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.

Input

The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.

The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.

Output

Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.

Examples
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
Note

In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.

In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.

In the third case, Masha will write infinitely integers 123.

题意:给你一个等比数列的初项 公比  数字的上界 现在写出满足的项 有m个不能出现的数字 问能写出多少项

题解:暴力

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
ll b1,q,l,m;
ll exm;
map<ll,int>mp;
ll ans=;
int main()
{
scanf("%I64d %I64d %I64d %I64d",&b1,&q,&l,&m);
for(ll i=;i<=m;i++)
{
scanf("%I64d",&exm);
mp[exm]=;
}
for(int i=;i<=;i++)
ans=;
for(int i=;i<;i++)
{
if(abs(b1)>l) break;
if(mp[b1]!=) ans++;
b1*=q;
}
if(ans>)
printf("inf\n");
else
printf("%I64d\n",ans);
return ;
}
C. Functions again
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:

In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.

Input

The first line contains single integer n (2 ≤ n ≤ 105) — the size of the array a.

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

Output

Print the only integer — the maximum value of f.

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

In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].

In the second case maximal value of f is reachable only on the whole array.

题意:   给你一个长度为n的数列 对于这个数列输出最大的f(l,r)

题解:处理出每一项绝对值 求两遍最大子序列和

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
int n;
ll a[];
ll b[];
ll c[];
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%I64d",&a[i]);
ll exm=;
for(int i=; i<n; i++)
{
exm=a[i]-a[i+];
if(exm<)
exm=-exm;
if(i%==)
{
b[i]=exm;
c[i]=-exm;
}
else
{
b[i]=-exm;
c[i]=exm;
}
}
ll sum=;
ll maxn1=-1e15,maxn2=-1e15;
for(int i=; i<n; i++)
{
sum+=b[i];
if(sum>maxn1)
{
maxn1=sum;
}
else if(sum<)
{
sum=;
if(i%==)
i--;
}
}
sum=;
for(int i=; i<n; i++)
{
sum+=c[i];
if(sum>maxn2)
{
maxn2=sum;
}
else if(sum<)
{
sum=;
if(i%==)
i--;
}
}
cout<<max(maxn1,maxn2)<<endl;
return ;
}

Codeforces Round #407 (Div. 2)A B C 水 暴力 最大子序列和的更多相关文章

  1. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #416 (Div. 2)A B C 水 暴力 dp

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

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

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

  4. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

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

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

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

  8. Codeforces Round #407 (Div. 1) B. Weird journey —— dfs + 图

    题目链接:http://codeforces.com/problemset/problem/788/B B. Weird journey time limit per test 2 seconds m ...

  9. Codeforces Round #407 (Div. 1)

    人傻不会B 写了C正解结果因为数组开小最后RE了 疯狂掉分 AC:A Rank:392 Rating: 2191-92->2099 A. Functions again 题目大意:给定一个长度为 ...

随机推荐

  1. Python数据结构 将列表作为栈和队列使用

    列表作为栈使用 Python列表方法使得列表作为堆栈非常容易,最后一个插入,最先取出(“后进先出”).要添加一个元素到堆栈的顶端,使用 append() .要从堆栈顶部取出一个元素,使用 pop()  ...

  2. Scrum立会报告+燃尽图(十月三十日总第二十一次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2290 项目地址:https://git.coding.net/zhang ...

  3. BundleCollection学习(一)

    工作中有同事提到了mvc4提供了css,js压缩功能.类BundleCollection所以搜集资料记录学习下. 学习中………… MVC中用 BundleCollection 压缩CSS时图片路径问题 ...

  4. TCP系列42—拥塞控制—5、Linux中的慢启动和拥塞避免(二)

    在本篇中我们继续上一篇文章wireshark的示例讲解,上一篇介绍了一个综合示例后,本篇介绍一些简单的示例,在读本篇前建议先把上一篇读完,为了节省篇幅,本篇只针对一些特殊的场景点报文进行讲解,不会像上 ...

  5. Mac下Git的基础操作

    目前最火的版本控制软件是Git了吧,今天简单梳理一下Mac下Git的基础操作~~ 一.什么是Git Git是一个分布式代码管理工具,用于敏捷的处理或大或小的项目,类似的工具还有svn. 基于Git的快 ...

  6. RFID标签、读卡器、终端、接口的概念

    RFID标签:(引用)RFID无线射频识别是一种非接触式的自动识别技术,它通过射频信号自动识别目标对象并获取相关数据,识别工作无须人工干预,可工作于各种恶劣环境.RFID技术可识别高速运动物体并可同时 ...

  7. Sass & Scss & CSS3

    Sass & Scss & CSS3 Sass & Scss @mixin & @include & @import & variable https: ...

  8. h5端提示下载app

    // app下载提示 if (!sessionStorage.getItem("appDownloadTipClosed") && isAndroidOrIphon ...

  9. 【bzoj4372】烁烁的游戏 动态点分治+线段树

    题目描述 给一颗n个节点的树,边权均为1,初始点权均为0,m次操作:Q x:询问x的点权.M x d w:将树上与节点x距离不超过d的节点的点权均加上w. 输入 第一行两个正整数:n,m接下来的n-1 ...

  10. 转--- 秒杀多线程第七篇 经典线程同步 互斥量Mutex

    阅读本篇之前推荐阅读以下姊妹篇: <秒杀多线程第四篇一个经典的多线程同步问题> <秒杀多线程第五篇经典线程同步关键段CS> <秒杀多线程第六篇经典线程同步事件Event& ...