Guest User

Error only in one test case, when n =10^5

a guest
Dec 7th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.   ios_base::sync_with_stdio(false);
  8.    cin.tie(NULL);
  9.    cout.tie(NULL);
  10.   int t;
  11.   cin>>t;
  12.   int arr[t];
  13.   int arrfreq[t];
  14.   int sum=1;
  15.   for(int i=0;i<t;i++ )
  16.   {
  17.     cin>>arr[t];
  18.     sum+=arr[t];
  19.     arrfreq[i]=sum;
  20.  
  21.  
  22.   }
  23.  
  24.  
  25.  
  26. int m;
  27. cin>>m;
  28. int qsn[m];
  29. int k;
  30. for(int i =0;i<m;i++)
  31. {
  32.   cin>>qsn[i];
  33.  
  34.    
  35.  
  36. }
  37.  
  38. for(int j =0;j<t;j++)
  39. {
  40.     if(k<arrfreq[j])
  41.     {
  42.       cout<<j+1<<"\n";
  43.       break;
  44.  
  45.     }
  46.     if(k==arrfreq[j])
  47.       {
  48.         cout<<j+2<<"\n";
  49.         break;
  50.       }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64. }
Add Comment
Please, Sign In to add comment