CodeForces 413C
来源:互联网 发布:先序遍历的非递归算法 编辑:程序博客网 时间:2024/05/20 01:39
Description
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2.
The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of thei-th question is ai points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price.
The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again.
All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve.
Input
The first line contains two space-separated integers n andm(1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line containsn space-separated integers a1, a2, ..., an(1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m distinct integersbi(1 ≤ bi ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n.
Output
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
Sample Input
4 11 3 7 53
18
3 210 3 82 3
40
2 2100 2001 2
400
#include<stdio.h>#include<algorithm>#include<string.h>#include<iostream>using namespace std;int main(){ long long i,a[111],b[111],c[111],n,m,sum,f; cin>>n>>m; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); sum=0; f=0; for(i=0;i<n;i++) { scanf("%lld",&a[i]); } for(i=0;i<m;i++) { scanf("%lld",&b[i]); } for(i=0;i<m;i++) { c[i]=a[b[i]-1]; } sort(b,b+m); for(i=0;i<n;i++) { if(b[f]-1!=i) { sum+=a[i]; } else { f++; } } sort(c,c+m); for(i=m-1;i>=0;i--) { if(c[i]>sum) { sum+=c[i]; } else { sum+=sum; } } cout<<sum<<endl; return 0;}
- CodeForces 413C Jeopardy!
- CodeForces 413C Jeopardy!
- CodeForces 413C
- Codeforces 413C Jeopardy!(贪心)
- Codeforces Round #413:C. Fountains
- Codeforces Round #413 C. Fountains
- codeforces round #413 C. Fountains
- Codeforces Round #413 Div. 2 C. Fountains
- Codeforces Round #413 C. Fountains 二分
- Codeforces Round #413 C-Fountains 树状数组
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- iOS程序员如何使用python写网路爬虫
- Git常用命令
- jstack,jmap,jstat
- 5个方法解决字符串包含关系
- Android开发:Fragment不同操作的生命周期
- CodeForces 413C
- NDK
- CAXA数控车2015免费版
- C语言学习之输入/输出函数第二讲
- XMLConfiguration读取XML文件
- 杂碎
- HBase常用操作之namespace
- Android 返回键取消dialog的监听
- CSS3 “搜索中...”“检测中...”效果