Codeforces 1077C Good Array

   https://vjudge.net/problem/CodeForces-1077C

题目:

Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1,3,3,7]a=[1,3,3,7] is good because there is the element a4=7a4=7 which equals to the sum 1+3+31+3+3.

You are given an array aa consisting of nn integers. Your task is to print all indices jj of this array such that after removing the jj-th element from the array it will be good (let's call such indices nice).

For example, if a=[8,3,5,2]a=[8,3,5,2], the nice indices are 11 and 44:

  • if you remove a1a1, the array will look like [3,5,2][3,5,2] and it is good;
  • if you remove a4a4, the array will look like [8,3,5][8,3,5] and it is good.

You have to consider all removals independently, i. e. remove the element, check if the resulting array is good, and return the element into the array.

Input

The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in the array aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106) — elements of the array aa.

Output

In the first line print one integer kk — the number of indices jj of the array aa such that after removing the jj-th element from the array it will be good (i.e. print the number of the nice indices).

In the second line print kk distinct integers j1,j2,…,jkj1,j2,…,jk in any order — niceindices of the array aa.

If there are no such indices in the array aa, just print 00 in the first line and leave the second line empty or do not print it at all.

Examples

Input1

    

Output1

3
4 1 5

Input2

4
8 3 5 2

Output2

2
1 4

Input3

5
2 1 2 4 3

Output3

0

Note

In the first example you can remove any element with the value 22 so the array will look like [5,1,2,2][5,1,2,2]. The sum of this array is 1010 and there is an element equals to the sum of remaining elements (5=1+2+25=1+2+2).

In the second example you can remove 88 so the array will look like [3,5,2][3,5,2]. The sum of this array is 1010 and there is an element equals to the sum of remaining elements (5=3+25=3+2). You can also remove 22 so the array will look like [8,3,5][8,3,5]. The sum of this array is 1616 and there is an element equals to the sum of remaining elements (8=3+58=3+5).

In the third example you cannot make the given array good by removing exactly one element.

分析:

首先题目意思很简单(废话不然能是C等级么),然后写的过程也没有什么困难,

附上错误代码一份~~.

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int n;
bool mmm;
struct point {
long long num;
int i;
} a[];
int ans,ansans;
int b[];
bool cmp(point x,point y) {
return x.num<y.num;
}
int main() {
cin>>n;
for(int i=; i<=n; i++) {
cin>>a[i].num;
ans+=a[i].num;
a[i].i=i;
}
sort(a+,a++n,cmp);
for(int i=; i<=n; i++) {
long long now=ans-a[i].num;
if(i==n) {
if(double(now/2.0)==a[n-].num) {
ansans++;
b[ansans]=a[i].i;
}
} else if(double(now/2.0)==a[n].num) {
ansans++;
b[ansans]=a[i].i;
}
}
cout<<ansans<<endl;
for(int i=; i<=ansans; i++)
cout<<b[i]<<" ";
cout<<endl;
return ;
}

看完之后,是不是感觉自己萌萌哒完全没有错误啊

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

慎重,这是一组很大的测试样例

那么温馨的附上我的第一个hack成功的样例一份~~~

诶结果不应该是0吗!!

为什么会出来那么那么多结果!!!!!!

为什么捏

因为单个数据1e6,有2e5个数据啊(无奈)

如果数据大了的话,加起来就是2e11了,

所以特殊样例专门把int类型爆了之后让int加会正数,然后巧妙的设置了一个坑~~~

不用long long的后果~~~~~~~~~~

附上正确代码一份:

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#include <list>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
struct A {
ll num,x;
} a[];
bool cmp(A a,A b) {
if(a.x < b.x)
return true;
if(a.x== b.x && a.num < b.num)
return true;
return false;
}
int main() {
re(a,);
ll n = ;
sld(n);
ll sum = ;
for(ll i = ; i< n; i ++) {
sld(a[i].x);
a[i].num = i;
sum += a[i].x;
//pld(sum) pn
}
sort(a,a+n,cmp);
ll count0 = ;
ll b[];
for(ll i = ; i < n-; i ++) {
if(sum - a[i].x - a[n-].x == a[n-].x) {
b[count0 ++] = a[i].num+;
}
} if(sum - a[n-].x - a[n-].x == a[n-].x) {
b[count0 ++] = a[n-].num+;
} if(count0 == ) {
pld(0ll) pn
} else {
pld(count0) pn
pld(b[])
for(ll i = ; i < count0; i ++) {
pk pld(b[i])
}
}
return ;
}

咦你居然发现了这里,这里是彩蛋哦

附上被我hack的萌新代码一份:

 #include<bits/stdc++.h>
using namespace std; #define ll long long
#define pii pair<ll,ll>
#define bug(a) cerr << #a << " : " << a << endl;
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL); const int MAX = 1e6; int main()
{
FastRead int n; cin >> n; int a[n+] , sum = ; multiset<int>s;
vector<int>ans; for(int i=;i<=n;i++)
cin >> a[i] , sum += a[i] , s.insert(a[i]); for(int i=;i<=n;i++)
{
s.erase(s.find(a[i])); if(*s.rbegin() == sum-a[i]-*s.rbegin())
ans.push_back(i); s.insert(a[i]);
} cout << ans.size() << endl;
for(auto i : ans)
cout << i << " ";
cout << endl; }

Codeforces 1077C Good Array 坑 C的更多相关文章

  1. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  2. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  3. codeforces 407C Curious Array

    codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...

  4. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  5. codeforces 86D : Powerful array

    Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...

  6. Codeforces 494D Upgrading Array

    http://codeforces.com/contest/494/problem/D 题意:给一个数组,和一个坏质数集合,可以无数次地让1到i这些所有数字除以他们的gcd,然后要求Σf(a[i])的 ...

  7. Codeforces 660A. Co-prime Array 最大公约数

    A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Codeforces 1023 D.Array Restoration-RMQ(ST)区间查询最值 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

    D. Array Restoration 这题想一下就会发现是只要两个相同的数之间没有比它小的就可以,就是保存一下数第一次出现和最后一次出现的位置,然后查询一下这个区间就可以,如果有0的话就进行填充. ...

  9. CodeForces ---596B--Wilbur and Array(贪心模拟)

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

随机推荐

  1. Scrapy实战篇(三)之爬取豆瓣电影短评

    今天的主要内容是爬取豆瓣电影短评,看一下网友是怎么评价最近的电影的,方便我们以后的分析,以以下三部电影:二十二,战狼,三生三世十里桃花为例. 由于豆瓣短评网页比较简单,且不存在动态加载的内容,我们下面 ...

  2. MPP数据库

    MPP数据库   版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/lyc417356935/article/details/45033069 MPP数据库定 ...

  3. expect login ssh

    #!/usr/bin/expect -f set pwffd [lindex $argv 0] spawn ssh cmesvr2i expect "*password:" sen ...

  4. 一个简单SpringBoot例子

    一:为什么使用springBoot: 有利于开发(整合框架,例如整合了springMVC,Mybatis等框架); 启动无需配置tomcat(java应用程序运行,实际以jar包运行),内置tomca ...

  5. final关键字特点

    一.final关键字修饰的类 无法被继承(即不能有子类) 二.final关键字修饰的方法不能被重写 三.final关键字修饰的变量成为常量(即不允许被修改) 开发中经常使用   

  6. Jmeter正则表达式提取器(转载)

    转载自 http://blog.csdn.net/qq_35885203 使用jmeter来测试时,经常会碰到需要上下文传输数据的情况,如登录后生成的token,在其他页面的操作,都需传入这个toke ...

  7. java中synchronized关键字分析

    今天我们来分析一下java中synchronized关键字.首先来看一段java代码:(本地编译环境为mac,jdk1.8的环境) Demo.java package com.example.spri ...

  8. <记录>TP5 关联模型使用(嵌套关联、动态排序以及隐藏字段)

    在数据库设计中,常常会有如下这种关联模型,分类表中一条分类对应多个商品表中的商品 如果要获得分类表中每条分类 以及 对应的商品的信息,则需要先查询分类表中的数据,然后根据结果遍历查询商品表,最后把数据 ...

  9. HTML-全局属性 / 事件属性(转)

    拷贝自:< http://www.runoob.com > HTML 全局属性 New : HTML5 新属性. 属性 描述 accesskey 设置访问元素的键盘快捷键. class 规 ...

  10. 使用swiper插件,隐藏swiper后再显示,不会触发自动播放的解决办法

    问题: 项目中有一个需求,当点击P1时,两个页面进行轮播.当点击P2时,页面不轮播. 设置好以后,点击P2,再点击P1,此时页面不能自动轮播,只能手动触发. 解决: 在轮播器配置里,配置observe ...