Contest (nefu.edu.cn)
Problem:G
Time Limit:2000ms
Memory Limit:65535K
Description
Catly有k个序列,每个序列有ni个元素,Catly想知道是否在k个序列中有两个序列,p和q,只要删除p中一个元素和q中一个元素,能使得q中元素和等于q中元素和
Input
第一行一个k(2<=k<=2e5) 代表有k个序列
接下来有2*k行,一行为ni(1<=ni<=2e5)代表第i个序列有多少个元素,数据保证k<=n1+...+nk<=2e5
下面一行有ni个数字aj(-10000<=aj<=10000)代表第i个序列中的元素
Output
如果有输出YES,并输出是哪两个序列x,y(x
Sample Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Sample Output
YES
1 2
unordered_map<int, pair<int, int>>mp;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
for (int j = 1; j <= n; j++) {
if (!mp[sum - arr[j]].first)mp[sum - arr[j]].first = i;
else if (!mp[sum - arr[j]].second && mp[sum - arr[j]].first != i)
mp[sum - arr[j]].second = i;
for (unordered_map<int, pair<int, int>>::iterator i = mp.begin(); i != mp.end();i++) {
if (i->second.second && i->second.first) {
int b = i->second.second;
if (x + y > a + b || (x + y == a + b && b < y)) {
printf("YES\n%d %d\n", x, y);