Hustlingbeast_Anish

Untitled

Mar 7th, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1.  
  2. #include<bits/stdc++.h>
  3. #include <algorithm>
  4. #define lli long long int
  5. #define li long int
  6. #define mod 1000000007
  7. #define ld long double
  8. #define F first
  9. #define S second
  10. #define PB push_back
  11. #define MP make_pair
  12. #define REP(i,a,b) for (int i = a; i < b; i++)
  13. using namespace std;
  14.  
  15. int main(){
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(NULL);
  18.        
  19.     int n;
  20.     cin>>n;
  21.  
  22.     map<int,int> m;
  23.  
  24.     int k;
  25.     cin>>k;
  26.  
  27.     int arr[n];
  28.     for (int i = 0; i < n; i++)
  29.     {  
  30.         cin>>arr[i];
  31.     }
  32.    
  33.  
  34.     for (int i = 0; i < n-k+1; i++)
  35.     {   int ans=0;
  36.         for (int j = 0; j < k; j++)
  37.         {
  38.            ans=ans+arr[j];
  39.         }
  40.         m.insert({ans,i+1});
  41.     }
  42.    
  43.     cout<<m.size()<<endl;
  44.    
  45.     for (auto pr:m)
  46.     {
  47.         cout<<pr.first<<" "<<pr.second<<endl;
  48.     }
  49.    
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment