Codeforces Round #486 (Div. 3)-C. Equal Sums

时间:2023-02-25 12:06:24
C. Equal Sums
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given kk sequences of integers. The length of the ii-th sequence equals to nini.

You have to choose exactly two sequences ii and jj (i≠ji≠j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence ii (its length will be equal to ni−1ni−1) equals to the sum of the changed sequence jj (its length will be equal to nj−1nj−1).

Note that it's required to remove exactly one element in each of the two chosen sequences.

Assume that the sum of the empty (of the length equals 00) sequence is 00.

Input

The first line contains an integer kk (2≤k≤2⋅1052≤k≤2⋅105) — the number of sequences.

Then kk pairs of lines follow, each pair containing a sequence.

The first line in the ii-th pair contains one integer nini (1≤ni<2⋅1051≤ni<2⋅105) — the length of the ii-th sequence. The second line of the ii-th pair contains a sequence of nini integers ai,1,ai,2,…,ai,niai,1,ai,2,…,ai,ni.

The elements of sequences are integer numbers from −104−104 to 104104.

The sum of lengths of all given sequences don't exceed 2⋅1052⋅105, i.e. n1+n2+⋯+nk≤2⋅105n1+n2+⋯+nk≤2⋅105.

Output

If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers ii, xx (1≤i≤k,1≤x≤ni1≤i≤k,1≤x≤ni), in the third line — two integers jj, yy (1≤j≤k,1≤y≤nj1≤j≤k,1≤y≤nj). It means that the sum of the elements of the ii-th sequence without the element with index xx equals to the sum of the elements of the jj-th sequence without the element with index yy.

Two chosen sequences must be distinct, i.e. i≠ji≠j. You can print them in any order.

If there are multiple possible answers, print any of them.

Examples
input
Copy
2
5
2 3 1 3 2
6
1 1 2 2 2 1
output
Copy
YES
2 6
1 2
input
Copy
3
1
5
5
1 1 1 1 1
2
2 3
output
Copy
NO
input
Copy
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
output
Copy
YES
2 2
4 1
Note

In the first example there are two sequences [2,3,1,3,2][2,3,1,3,2] and [1,1,2,2,2,1][1,1,2,2,2,1]. You can remove the second element from the first sequence to get [2,1,3,2][2,1,3,2] and you can remove the sixth element from the second sequence to get [1,1,2,2,2][1,1,2,2,2]. The sums of the both resulting sequences equal to 88, i.e. the sums are equal.

思路:好吧,这道题还是比较水的(原谅我的菜),本题的题意大概就是给N个序列,问里面是否有两个序列,在这两个序列中去掉其中一个数后他们的和相同。当时自己以想。。。WC序列这么多,怎么办???要是按照每个序列存下每一种可能map绝对炸啊。后来经过大佬指点,其实这个题并不难,原因就是我只需要找到一组即可,并且我考虑的是:和去掉一个元素的数值,我可以在每个序列输入完以后得到和,再循环一次得到减去一个元素的集合,然后保存每一种可能,并把它所在的序列号,和位置都存下来即可。然后后面的循环中判断是否出现过这个数字。出现过就不循环进行以上操作,直接把剩余数输入即可,然后输出这种情况,要注意有可能在自己序列中出现和自己相同的情况,需要舍去。

实现:由于值有可能为负数,因此判断这个值是否存在,可以用一个map映射即可,对于存这个数值所在的行和列,由于数值的行和列,可以结构体数组或者二维map即可

 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
using namespace std;
const int maxx=;
map<int,map<int,int> >p;//存这个数值对应所在的序列和序列中的位置
map<int,int>vis;//是否前面有和这个数值一样的数
int main()
{
int k,n,sum;
int a[maxx];
while(~scanf("%d",&k))
{
sum=;
int flag=;
vis.clear();
int ans11,ans12,ans21,ans22;
for(int i=;i<=k;i++)
{
scanf("%d",&n);
sum=;
for (int j=; j<=n; j++)
{
scanf("%d",&a[j]);
sum+=a[j];
}
if (flag)continue;//如果已经找到这组数值就不进行下次操作
for(int j=;j<=n;j++)
{
int tmp=sum-a[j];
if (vis[tmp]== || p[tmp][]==i)//如果这个值没有存在过 或者 这个值相同的出现在同一个序列中
{
vis[tmp]=;
p[tmp][]=i;
p[tmp][]=j;
}
else//存在所在序列和位置
{
flag=;
ans11=p[tmp][];
ans12=p[tmp][];
ans21=i;
ans22=j;
}
}
}
if (flag==)printf("NO\n");
else
{
printf("YES\n");
printf("%d %d\n",ans11,ans12);
printf("%d %d\n",ans21,ans22);
}
}
return ;
}

Codeforces Round #486 (Div. 3)-C. Equal Sums的更多相关文章

  1. Codeforces Round &num;486 &lpar;Div&period; 3&rpar; C &quot&semi;Equal Sums&quot&semi; (map&plus;pair&lt&semi;&gt&semi;)

    传送门 •题意 给k个数列,从中k个数列中找出任意2个数列 i ,j 使得数列i删除第x个数,和数列j删除第y个数的和相等 若存在,输出 i ,x 和 j,y •思路 每个数列之间的联系为数列的和之间 ...

  2. Codeforces Round &num;486 &lpar;Div&period; 3&rpar; F&period; Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  3. Codeforces Round &num;486 &lpar;Div&period; 3&rpar; E&period; Divisibility by 25

    Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. Codeforces Round &num;486 &lpar;Div&period; 3&rpar; D&period; Points and Powers of Two

    Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...

  5. Codeforces Round &num;486 &lpar;Div&period; 3&rpar; A&period; Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  6. Codeforces Round &num;486 &lpar;Div&period; 3&rpar;-B&period; Substrings Sort

    B. Substrings Sort time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. Codeforces Round &num;486 &lpar;Div&period; 3&rpar;988D&period; Points and Powers of Two

    传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...

  8. Codeforces Round &num;579 &lpar;Div&period; 3&rpar; B Equal Rectangles、C&period; Common Divisors

    B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个 ...

  9. Codeforces Round &num;486 &lpar;Div&period; 3&rpar;988E&period; Divisibility by 25技巧暴力&vert;&vert;更暴力的分类

    传送门 题意:给定一个数,可以对其做交换相邻两个数字的操作.问最少要操作几步,使得可以被25整除. 思路:问题可以转化为,要做几次交换,使得末尾两个数为00或25,50,75: 自己一开始就是先for ...

随机推荐

  1. sql server死锁神器

    参考文章: http://blogs.msdn.com/b/sqlserverfaq/archive/2013/04/27/an-in-depth-look-at-sql-server-memory- ...

  2. 深入浅出Spring(五) SpringMVC

    上一篇深入浅出Spring(四) Spring实例分析的博文中,咱们已经可以了解Spring框架的运行原理和实现过程,接下来咱们继续讲解Spring的一个延伸产品——Spring MVC 1.Spri ...

  3. HDU5778 abs

    http://acm.hdu.edu.cn/showproblem.php?pid=5778 思路:只有平方质因子的数,也就是这题所说的   y的质因数分解式中每个质因数均恰好出现2次  满足条件的数 ...

  4. cmake 手册系列

    http://www.cnblogs.com/coderfenghc/archive/2012/06/16/CMake_ch_01.html

  5. Open vswitch 之Qos rate-limiting 原理

    Openvswitch之Qos rate-limiting原理 OVS的qosrate-limiting功能是采用令牌桶(Token-Bucket)机制进行的.这里的“令牌桶”是指网络设备的内部存储池 ...

  6. 基于TypeScript装饰器定义Express RESTful 服务

    前言 本文主要讲解如何使用TypeScript装饰器定义Express路由.文中出现的代码经过简化不能直接运行,完整代码的请戳:https://github.com/WinfredWang/expre ...

  7. 多线程下载图片,同步下载http&colon;&sol;&sol;www&period;importnew&period;com&sol;15731&period;html

    package mutiDownload; import java.io.IOException; import java.io.InputStream; import java.io.RandomA ...

  8. SpringCloud使用Nacos服务发现实现远程调用

    本文使用SpringCloud结合Nacos服务发现,Feign远程调用做一个简单的Demo. 1 Nacos 关于Nacos之前写了两篇文章关于SpringBoot对它的使用,感兴趣可以查看一下. ...

  9. &lbrack;论文阅读&rsqb;Object detection at 200 Frames Per Second

    本文提出了一个有效且快速的目标检测器,该目标检测器得速度可以达到200+fps,在Pascal VOC-2007上的mAP比Tiny-Yolo-v2高出14. 本文从以下三个方面对网络进行改进. 网络 ...

  10. 安装mysql时包冲突解决方法

    报错信息如下: 解决办法: 在卸载代码上加上不检查关联信息即可(rpm -ev mysql-libs-5.1.73-7.el6.x86_64 --nodeps) 检查服务器是否还有mysql安装包:r ...