codechef Chef and easy problem
来源:互联网 发布:明朝那些事儿错误知乎 编辑:程序博客网 时间:2024/05/29 18:21
Problem Description
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of Ttest cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
Output
For each test case, output a single line containg the maximum number of stones that Chef can remove.
Constraints
- 1 ≤ Ai ≤ 109
- Subtask 1 (35 points): T = 10, 1 ≤ N ≤ 1000
- Subtask 2 (65 points): T = 10, 1 ≤ N ≤ 105
Example
Input:
231 2 331 2 1Output:
43
题解
贪心。注意lld。
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#define ll long longusing namespace std;int T,n,a[100002];ll ans;void work(){scanf("%d",&n);ans=0;int i;for(i=1;i<=n;i++) scanf("%d",&a[i]);sort(a+1,a+n+1);for(i=n;i>=1;i-=2) ans+=a[i];printf("%lld\n",ans);}int main(){scanf("%d",&T);while(T--) work();return 0;}
- codechef Chef and easy problem
- codechef Chef and easy problem 2
- CodeChef Chef and Churu Problem
- CodeChef Chef and Segments
- codechef Chef and sequence
- codechef Chef and Swaps
- Codechef Chef and Reversing
- Codechef Chef and Frogs
- Codechef Chef and Churu
- 【CodeChef】 Chef and Stones
- 【CodeChef】Chef and Interview
- codechef Chef and Churu
- codechef Chef and Left-Right
- codechef-Chef and Prime Divisors
- CodeChef Chef and Strange Operations
- Chef and Graph Queries (codechef)
- codechef Chef and The Right Triangles 题解
- codechef Chef and Rainbow Array - 2
- TexturePacker 算法
- 管理好企业中的“老人”也是门艺术
- leetcode: Interleaving String
- IOS上路_01-Win7+VMWare9+MacOSX10.8+XCode4.6.3
- MySQL优化大全
- codechef Chef and easy problem
- qt 自定义外形 qpushbutton
- GitHub创建SSH Keys
- virtualbox 共享目录设置
- linux find命令格式及find命令详解
- CheckBoxList多条件取值,sql查询
- vc++开发简单的半透明窗口程序示例
- ligerUI ComboBox多级菜单无刷新联动
- JavaScript 数据类型