运用hash表 边存边找 ,可再o(N)复杂度内找到特定元素
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; unordered_map<LL,PII> has; int main() { int T; cin>>T; for (int i = 1; i <=T; i ++ ) { int n; cin>>n; LL sum=0; int a[n+1]; for(int j=1;j<=n;j++){ cin>>a[j]; sum+=a[j]; } // cout<<n<<' '<<sum<<endl; for(int j=1;j<=n;j++){ LL t=sum-a[j]; if(has.count(t)&&has[t].first!=i){ puts("YES"); cout<<has[t].first<<' '<<has[t].second<<endl; cout<<i<<' '<<j<<endl; return 0; }else if(!has.count(t)){ has[t]={i,j}; } } } puts("NO"); return 0; }