题干:

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

2
5
2 3 1 3 2
6
1 1 2 2 2 1

Output

YES
2 6
1 2

Input

3
1
5
5
1 1 1 1 1
2
2 3

Output

NO

Input

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

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 个整数数列 a1,a2,…an ,每个数列的长度为Li。

请你找出两个编号不同的数列,并从这两个数列中各恰好删除一个数,使得这两个数列的和相等。

解题报告:

首先看到读入这么多数据,所以肯定不能用数组保存下来在离线处理,肯定是边读入边判断的,这种题通常是读入的同时,用数据结构记录一些信息,然后用后面读入的数去判断的。这样就很容易想到,需要记录的信息就是有哪些数字是可用的,题意都不用转化,模拟题意就行了:删去一个数求和。所以先记录下sum,然后再减去每一个数,用map记录下是第几个序列的第几个位置,方便后来查询的时候输出答案。

然后为了处理不在同一个序列中,这个问题,刚开始想把序列离散化了,后来想了想不行,,因为还需要记录当前数的位置,所以干脆直接判断原来那个数是否也是第i个序列。或者还有一种处理方法

AC代码:(156ms,改成uset则124ms)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> PII;//pair<第i个序列 , 第j个字符>
const int MAX = 2e5 + 5;
int a[MAX];
map<int,PII> mp;
set<int> ss;
int main()
{int n,len,flag = 0;int ans1,ans2,ans3,ans4;cin>>n;for(int i = 1; i<=n; i++) {scanf("%d",&len);int sum = 0;for(int j = 1; j<=len; j++) scanf("%d",a+j),sum += a[j];if(flag) continue;for(int j = 1; j<=len; j++) {int tmp = sum - a[j];if(ss.count(tmp) && mp[tmp].fi != i) {flag = 1;ans1 = mp[tmp].fi; ans2 = mp[tmp].se;ans3 = i; ans4 = j;}else {ss.insert(tmp);mp[tmp] = pm(i,j);}}} if(flag) {puts("YES");printf("%d %d\n%d %d\n",ans1,ans2,ans3,ans4);}else {puts("NO");}return 0 ;}

另一种处理办法:(78ms)

 for(int i = 1; i<=n; i++) {scanf("%d",&len);int sum = 0;for(int j = 1; j<=len; j++) scanf("%d",a+j),sum += a[j];if(flag) continue;for(int j = 1; j<=len; j++) {int tmp = sum - a[j];if(mp.count(sum - a[j])) {flag = 1;ans1 = mp[tmp].fi; ans2 = mp[tmp].se;ans3 = i; ans4 = j;}}for(int j = 1; j<=len; j++) {int tmp = sum - a[j];mp[tmp] = {i,j};}} 

错误代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int> PII;//pair<第i个序列 , 第j个字符>
const int MAX = 2e5 + 5;
int a[MAX];
map<int,PII> mp;
set<int> ss;
int main()
{int n,len,flag = 0;int ans1,ans2,ans3,ans4;cin>>n;for(int i = 1; i<=n; i++) {scanf("%d",&len);int sum = 0;for(int j = 1; j<=len; j++) scanf("%d",a+j),sum += a[j];sort(a+1,a+len+1);int x = unique(a+1,a+len+1) - a - 1;// printf("x = %d\n",x);if(flag) continue;for(int j = 1; j<=x; j++) {int tmp = sum - a[j];if(ss.count(tmp)) {flag = 1;ans1 = mp[tmp].fi;ans2 = mp[tmp].se;ans3 = i;ans4 = j;}else {ss.insert(tmp);mp[tmp] = pm(i,j);}}} if(flag) {puts("YES");printf("%d %d\n%d %d\n",ans1,ans2,ans3,ans4);}else {puts("NO");}return 0 ;}

【CodeForces - 988C 】Equal Sums (思维,STLmap,STLset,tricks)相关推荐

  1. 【Codeforces - 900C】Remove Extra One(思维,STLset,tricks)

    题干: You are given a permutation p of length n. Remove one element from permutation to make the numbe ...

  2. CF思维联系– Codeforces-988C Equal Sums (哈希)

    ACM思维题训练集合 You are given k sequences of integers. The length of the i-th sequence equals to ni.You h ...

  3. Codeforces Round #486 (Div. 3) C Equal Sums (map+pair)

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

  4. CF--思维练习-- CodeForces - 215C - Crosses(思维题)

    ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...

  5. Make Product Equal One(思维)

    Make Product Equal One - CodeForces 1206B - Virtual Judge (csgrandeur.cn) 想复杂了,这题考的边界情况对我来说有点多,挺好的一题 ...

  6. CodeForces - 1213A Chips Moving (思维 数学)

    CodeForces - 1213A Chips Moving 题目: You are given n chips on a number line. The i-th chip is placed ...

  7. CodeForces - 1593G Changing Brackets(思维)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的括号序列,其中包含了 {(,),[,]}\{(,),[,]\}{(,),[,]} 四种括号,现在可以进行两种操作: 将括号反转,代价为 000, ...

  8. CodeForces - 1567C Carrying Conundrum(思维/状压)

    题目链接:点击查看 题目大意:规定加法中使用隔项进位,问给定的 nnn 有多少种方案可以通过 "隔项进位加法" 得到 题目分析:隔项进位意味着奇偶位置的数字互不影响,所以将奇偶位置 ...

  9. CodeForces - 1535C Unstable String(思维)

    题目链接:点击查看 题目大意:规定一个字符串将问号都替换成 000 或 111 后满足 010101 交替的话,该字符串是合法的,现在给出一个长度为 nnn 的字符串,求合法子串的个数 题目分析:两种 ...

最新文章

  1. 后台设置 datakeynames
  2. flex容器属性(一)
  3. php 加密解密函数封装
  4. “几乎看不见”的铰链!可折叠iPhone要来了?
  5. MySQL Hex函数使用详解
  6. 对 比 学 习 小 综 述
  7. 2021 测试工作年终总结
  8. kotlin运行_Kotlin允许,运行,也适用于
  9. 任务方案思考:句子相似度和匹配
  10. 【车道线检测与寻迹】【1月8日】车辆、道路模型与道路跟踪
  11. Android游戏引擎汇总,android开发模拟器
  12. 等额本息计算 java 代码
  13. 解决多线程编程中大并发数等待唤醒的问题
  14. 【区块链扩容】侧链技术 Plasma(Layer 2)
  15. linux内核源码lxr,配置glimpse与LXR读取linux内核源码
  16. C# WPF MVVM框架搭建
  17. 电力电子与电力传动类毕业论文文献包含哪些?
  18. 谷歌发布Android auto车载系统对当前车载市场的影响
  19. MVP架构开发的鼠绘漫画客户端
  20. 怎么取消微信充值服务器,微信亲密充充值提醒怎么取消?

热门文章

  1. 【转贴】利用 Javascript 获取 URL 参数(适合IE、FF)
  2. [Leedcode][JAVA][面试题 01.07][找规律][旋转数组]
  3. oracle sql-1,Oracle – Oracle SQL(1)
  4. java延迟覆盖_高效Java第九条覆盖equals时总要覆盖hashCode
  5. java版本streamgobbler_java调用本地命令 Runtime class's exec() method
  6. 毕业论文排版之Word 中公式居中,编号靠右该怎么设置(针对左右不对称页边距)
  7. 计算机硬件的维护知识,电脑放了一年开不了机 电脑硬件维护常识要点有哪些...
  8. python 项目实战视频_腾讯视频 Python 爬虫项目实战
  9. OpenXLSX 中文字段读取问题
  10. scrapy 中不同页面的拼接_scrapy使用技巧总结