#include <cmath> #include <vector> #include <algorithm> #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=10010; int f[N]; ll s[N]; vector<int>res{10010,10010}; int main() { int n, k ; cin>>n>>k; for(int i=1;i<=n;i++)cin>>f[i]; for(int i=1;i<=n;i++){ s[i]=s[i-1]+f[i]; } bool flag=false; unordered_map<ll,int>has; has[0]=0; for(int i=1;i<=n;i++){ if(has.find(s[i]-k)!=has.end()&&res[0]>has[s[i]-k]+1){ flag=true; res={has[s[i]-k]+1,i}; } if(has.find(s[i])==has.end())has[s[i]]=i; } if(!flag)cout<<"No Solution"<<endl; else cout<<res[0]<<" "<<res[1]<<endl; return 0; }
原文地址:https://www.cnblogs.com/programyang/p/11217570.html
时间: 2024-10-12 16:45:45