由于是输出任意一组解,可以将价值从小到大进行排序,第一个人只选第一个,第二个人选其余的。再比较一下第一个人选的元素和第二个人所选元素和是否相等即可。由于已将所有元素价值从小到大排过序,这样可以保证在有解的情况下一定可以构造出可行解。

Code:

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 3;
int a[maxn], A[maxn];
bool cmp(int i,int j) { return a[i] < a[j];}
int main()
{
int n;
cin >> n;
for(int i = 1;i <= n; ++i){ cin >> a[i]; A[i] = i; }
if(n == 1) { cout << -1 ; return 0; }
sort(A + 1, A + 1 + n,cmp);
int sum = 0;
for(int i = 2; i <= n; ++i) sum += a[A[i]];
if(sum == a[A[1]]) cout << -1;
else cout << 1 << "\n" << A[1] ;
return 0;
}

Codeforces Round #493 (Div. 2) A. Balloons 贪心水题的更多相关文章

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

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

  2. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

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

  4. Codeforces Round #249 (Div. 2)B(贪心法)

    B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #493 (Div 2) (A~E)

    目录 Codeforces 998 A.Balloons B.Cutting C.Convert to Ones D.Roman Digits E.Sky Full of Stars(容斥 计数) C ...

  6. Cutting Codeforces Round #493 (Div. 2)

    Cutting There are a lot of things which could be cut — trees, paper, “the rope”. In this problem you ...

  7. Codeforces Round #493 (Div. 2)

    C - Convert to Ones 给你一个01串 x是反转任意子串的代价 y是将子串全部取相反的代价 问全部变成1的最小代价 两种可能 一种把1全部放到一边 然后把剩下的0变成1  要么把所有的 ...

  8. Codeforces Round #493 (Div. 1)

    A. /* 发现每次反转或者消除都会减少一段0 当0只有一段时只能消除 这样判断一下就行 */ #include<cstdio> #include<algorithm> #in ...

  9. Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目

    D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. BZOJ 1221 [HNOI2001] 软件开发 费用流_建模

    题目描述:   某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员每天提供 ...

  2. 【数据分析】算法+Echarts小练

    ''' 处理逻辑: 按number去处理 先遍历所有的number挨个去找有没有在列表里的,在列表里的拿出另外一个append 把number去除的列表 ''' li = [] with open(r ...

  3. 路飞学城Python-Day96

    51-数据库表关系之一对多 为什么有多表的概念? 一个Book有单表的时候只能查询Book表中的内容,要想查询更多的出版社的信息,需要再将单表的内容不断更新 导致单表会存储大量的重复的信息,浪费了大量 ...

  4. linux 遇到(vsftpd)—500 OOPS:chroot

    今天在用vsftpd 时出现一个问题: 500 OOPS:chroot 解决办法: 1.关闭SELINUX [root@localhost ~]#vi /etc/sysconfig/selinux # ...

  5. leetCode笔记--(1)

    陪朋友刷题,记录下. 1.Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operato ...

  6. 地图API示例

    http://developer.baidu.com/map/jsdemo.htm#i6_2

  7. FreeMarker hello

    一.什么是 FreeMarker FreeMarker 是一个用 Java 语言编写的模板引擎,它基于模板来生成文本输出.FreeMarker 与 Web 容器无关,即在 Web 运行时,它并不知道  ...

  8. [ASP.NET]EF跨项目调用问题

    在一个项目中调用另一个项目中的模型,在该项目中添加一个模型,解决自动提示问题using问题

  9. [SharePoint2010开发入门经典]创建你的第一个SPS2010程序

    本章概要: 1.创建一个解决方案,使他能读写数据从列表中,使用服务器端对象模型和可视的web部件 2.使用VS2010构建部署解决方案 3.使用图标web部件渲染列表数据 4.在一个解决方案中集成不同 ...

  10. js面向对象编程: js类定义函数时prototype和this差别?

    在面向对象编写js脚本时,定义实例方法主要有两种 例如以下: function ListCommon2(afirst) { var first=afirst; this.do1=function () ...