博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 17
阅读量:4991 次
发布时间:2019-06-12

本文共 4339 字,大约阅读时间需要 14 分钟。

A. k-th divisor
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.

Divisor of n is any such natural number, that n can be divided by it without remainder.

Input

The first line contains two integers n and k (1 ≤ n ≤ 1015, 1 ≤ k ≤ 109).

Output

If n has less than k divisors, output -1.

Otherwise, output the k-th smallest divisor of n.

Examples
Input
4 2
Output
2
Input
5 3
Output
-1
Input
12 5
Output
6
Note

In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.

In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.

1 #include 
2 #define ll long long int 3 #define N 1000005 4 #define mem(a) memset(a,0,sizeof(a)) 5 ll k[N]; 6 using namespace std; 7 ll n; 8 int m; 9 set
s;10 int main(){11 cin>>n>>m;12 int cnt=sqrt(n);13 for(int i=1;i<=cnt;i++){14 if(n%i==0){15 s.insert(i);16 s.insert(n/i);17 }18 }19 set
::iterator it;20 bool prime=true;21 for(it=s.begin();it!=s.end();it++){22 m--;23 if(m==0){24 cout<<*it<

 

 

B. USB vs. PS/2
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!

The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.

You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.

You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.

Input

The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.

The next line contains one integer m (0 ≤ m ≤ 3·105)  — the number of mouses in the price list.

The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≤ vali ≤ 109)  — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.

Output

Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.

Example
Input
2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2
Output
3 14
Note

In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.

 

1 #include 
2 #define ll long long int 3 #define N 300050 4 using namespace std; 5 multiset
c,t,r; 6 ll n,m,k,s; 7 ll x; 8 ll inde; 9 string st;10 int main(){11 cin>>n>>m>>k>>s;12 while(s--){13 cin>>x>>st;14 if(st[0]=='U'){15 c.insert(x);16 }else{17 t.insert(x);18 }19 }20 multiset
::iterator it;21 ll cnt=0;22 for(it=c.begin();it!=c.end();it++){23 if(n){24 cnt+=*it;25 inde++;26 n--;27 }else{28 r.insert(*it);29 }30 }31 for(it=t.begin();it!=t.end();it++){32 if(m){33 cnt+=*it;34 inde++;35 m--;36 }else{37 r.insert(*it);38 }39 }40 for(it=r.begin();it!=r.end();it++){41 if(k){42 cnt+=*it;43 inde++;44 k--;45 }46 }47 cout<
<<" "<
<

 

转载于:https://www.cnblogs.com/zllwxm123/p/7630100.html

你可能感兴趣的文章
spark-submit配置说明
查看>>
C#定时任务
查看>>
Android属性动画
查看>>
第九周作业
查看>>
hihocoder 1523 数组重排2+思维
查看>>
004 面向对象1
查看>>
C语言——贪吃蛇(第二阶段小蛇的移动
查看>>
牛客网——二叉树
查看>>
MyEclipse反编译插件的安装
查看>>
php RSA 简单实现
查看>>
python_Day4
查看>>
mongo3.0用户设置转(3)
查看>>
2018.3 强网杯 部分writeup
查看>>
架构师速成6.18-初中书单资料推荐
查看>>
linux系统的安装
查看>>
Java设计模式菜鸟系列(十三)建模和实现状态模式
查看>>
《Hadoop》对于高级编程Hadoop实现构建企业级安全解决方案
查看>>
android ndk通过遍历和删除文件
查看>>
Notification(一个)——使用演示样本的基础知识
查看>>
《算法导论》为什么经典
查看>>