2 solutions

  • 1
    @ 2025-8-29 14:58:23
    #include<bits/stdc++.h>
    using namespace std;
    int a[100010],b[100010],k;
    int main(){
    	int n,m,k;
    	cin>>n>>m>>k; 
    	for(int i=1;i<=n;i++)cin>>a[i];
    	for(int i=1;i<=n;i++)cin>>b[i];
    	for(int l=1,r=m;l<=n&&r>=1;){
    		if(a[l]+b[r]>k)r--;
    		else if(a[l]+b[r]<k)l++;
    		else{
    			cout<<l-1<<' '<<r-1;
    			return 0;
    		}
    	}
    	return 0;
    }
    
    
    • -1
      @ 2025-7-19 19:08:41
      #include<bits/stdc++.h>
      using namespace std;
      const int N=100010;
      int a[N],b[N],k;
      int main()
      {
          int n,m,k;
          cin>>n>>m>>k;
          for(int i=1;i<=n;i++) cin>>a[i];
          for(int i=1;i<=m;i++) cin>>b[i];
          for(int l=1,r=m;l<=n&&r>=1;)
          {
              if(a[l]+b[r]>k) r--; //当前和大了
              else if(a[l]+b[r]<k) l++; //当前和小了
              else //找到了对应的位置
              {
                  cout<<l-1<<" "<<r-1;
                  return 0;
              }
          }
          return 0;
      }
      
      • 1

      Information

      ID
      2881
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      5
      Tags
      # Submissions
      11
      Accepted
      3
      Uploaded By