codeforces 670A. Holidays

题目链接:

http://codeforces.com/contest/670/problem/A

题意:

A. Holidays

On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.

Output

Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.

Examples

Input

14

Output

4 4

Input

2

Output

0 2

Note

In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .

In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.

分析:

每周有7天,每周有2天的休息时间。问给出n,n代表有n天,问最少有几天休息时间,最多有几天休息时间。

如果是7的倍数,则定会每周休息2天。

最少时间:大于5为分界点

最大时间:大于2为分界点

代码:

#include<bits/stdc++.h>

using namespace std;

int main()
{
int n;
cin>>n;
int ans=n/7*2;
int t=n%7;
int minans;
int maxans; if(t>5) minans=t-5;
else minans=0;
if(t>2) maxans=2;
else maxans=t; cout<<minans+ans<<" "<<maxans+ans<<endl;
return 0;
}

codeforces 670B. Game of Robots

题目链接:

http://codeforces.com/contest/670/problem/B

题意:

In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.

At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.

Your task is to determine the k-th identifier to be pronounced.

Input

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ kmin(2·109, n·(n + 1) / 2).

The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Output

Print the k-th pronounced identifier (assume that the numeration starts from 1).

Examples

Input

2 2
1 2

Output

1

Input

4 5
10 4 18 3

Output

4

分析:

反向思维

代码:

#include<bits/stdc++.h>

using namespace std;
int a[100009]; int main()
{
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
} for(int i=1;i<=n;i++)
{
if(k<=i) break;
else k=k-i;
} cout<<a[k]<<endl;
return 0;
}

codeforces 670C. Cinema

题目链接:

http://codeforces.com/contest/670/problem/C

题意:

Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.

In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.

The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.

The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.

The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that is bjcj.

Output

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

Examples

Input

3
2 3 2
2
3 2
2 3

Output

2

Input

6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1

Output

1

分析:

根据数据分析可知用  map数组+struct排序  做

代码:

#include<bits/stdc++.h>

using namespace std;
map<int,int>s; struct p1
{
int a;
int b;
}P1[200009]; struct p
{
int c;
int d;
int t1;
int t2;
}P[200009]; bool cmp(p X,p Y)
{
if(X.t1==Y.t1) return X.t2>Y.t2;
else return X.t1>Y.t1;
}
int main()
{
int n,t,m;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&t);
s[t]++;
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&P1[i].a);
P[i].c=P1[i].a;
}
for(int i=1;i<=m;i++)
{
scanf("%d",&P1[i].b);
P[i].d=P1[i].b;
}
for(int i=1;i<=m;i++)
{
P[i].t1=s[P1[i].a];
P[i].t2=s[P1[i].b];
}
sort(P+1,P+m+1,cmp);
for(int i=1;i<=m;i++)
{
if(P[1].c==P1[i].a && P[1].d==P1[i].b)
{
cout<<i<<endl;
break;
}
}
return 0;
}

Codeforces Round #350 (Div. 2)解题报告的更多相关文章

  1. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  2. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  3. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  4. Codeforces Round #216 (Div. 2)解题报告

    又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<];    ,m2=;    ;i ...

  5. Codeforces Round #281 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...

  6. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  7. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  8. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

  9. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

随机推荐

  1. Mac中MacPorts安装和使用

    文章转载至http://www.zikercn.com/node/8 星期四, 06/07/2012 - 19:02 - 张慧敏 MacPorts简单介绍 MacPorts,以前叫做DarwinPor ...

  2. android内存的一点优化

    android手机给应用分配的内存通常是8兆左右,如果处理内存处理不当很容易造成OutOfMemoryError,我们的产品出现最多的错误也是OutOfMemoryError的异常, 在解决这个异常时 ...

  3. Eclipse 优化方法(经典收藏)

    第一步: 取消自动validationvalidation有一堆,什么xml.jsp.jsf.js等等,我们没有必要全部都去自动校验一下,只是需要的时候才会手工校验一下! 取消方法:windows–& ...

  4. 【jQuery】smartMenu右键自定义上下文菜单插件(似web QQ)

    (前端用重点整理博客地址)链接地址:http://www.cnblogs.com/atree/archive/2011/06/30/jQuery-smartMenu-javascript.html 一 ...

  5. OC中多线程的一些概念

    1.进程1.1>进程是指在系统中正在运行的一个应用程序(同时打开QQ和Xcode,系统会分别启动2个进程)1.2>每个进程之间是独立的,每个进程均运行在其专用的且受保护的内存空间内 2.线 ...

  6. 符号文件(.pdb)——Windows 应用程序调试必备

    最近在做项目需求过程中,时不时会遇到崩溃,总是异常中断,于是学习了windbg进行调试的一些基础,windbg在接下来文章进行更新,先介绍在windbg调试中一个重要文件(符号文件) 一.符号文件定义 ...

  7. jQuery Easy UI Resizable(调整大小)组件

    Resizable(调整大小)组件,easyui基础组件之中的一个.调整大小就是能够对元素能够拖着调整大小,这个组件不依赖于其它组件,使用比較简单,相关的属性.事件都 在样例中介绍了. 演示样例: & ...

  8. WF4.0——升级技能:托付应用

    回想: 在一个月前,我们刚刚回想了面对象至关重要的部分:托付,详细请移步我们博客:面向对象--一起来复习托付与事件!关于这篇博客的详细内容,不再赘述,在这里我们主要讨论在工作流中的应用及他的详细怎样解 ...

  9. linux命令:find

    先上例子: find ./*_src -type f | xargs grep -ils "date" 在指定的那些文件夹下面,递归寻找包含“date” 字符串的普通文件. fin ...

  10. Libgdx实现异步加载网络图片并保存到SD卡或者data/data目录下边

    Libgdx实现异步加载网络图片并保存到SD卡或者data/data目录下边,当本地有图片的时候,直接从本地读取图片,如果本地没有图片,将从服务器异步加载图片 package com.example. ...