ash_sinha

Untitled

Oct 7th, 2022
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. using namespace __gnu_pbds;
  4. using namespace std;
  5.  
  6. #define ff              first
  7. #define ss              second
  8. #define int             long long
  9. #define pb              push_back
  10. #define mp              make_pair
  11. #define pii             pair<int,int>
  12. #define vi              vector<int>
  13. #define mii             map<int,int>
  14. #define pqb             priority_queue<int>
  15. #define pqs             priority_queue<int,vi,greater<int> >
  16. #define setbits(x)      __builtin_popcountll(x)
  17. #define zrobits(x)      __builtin_ctzll(x)
  18. #define mod             1000000007
  19. #define inf             1e18
  20. #define ps(x,y)         fixed<<setprecision(y)<<x
  21. #define mk(arr,n,type)  type *arr=new type[n];
  22. #define w(x)            int x; cin>>x; while(x--)
  23. mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
  24. #define fastio          ios_base::sync_with_stdio(0); cin.tie(0);
  25.  
  26. int findEarlisetMonth(vector<int> a)
  27. {
  28.     int n=a.size(),ans_diff,ans_m=0;
  29.     for(int i=1;i<n;i++) a[i]+=a[i-1];
  30.     ans_diff = a[0] - ((a[n-1]-a[0])/(n-1));
  31.     ans_diff=abs(ans_diff);
  32.     ans_m=0;
  33.     for(int i=1;i<=n-2;i++)
  34.     {
  35.         int temp = ((a[i])/(i+1)) - ((a[n-1]-a[i])/(n-i-1));
  36.         temp=abs(temp);
  37.         if(temp<ans_diff){
  38.             ans_diff=temp;
  39.             ans_m=i;
  40.         }
  41.     }
  42.     return ans_m+1;
  43. }
  44.  
  45.  
  46. int32_t main()
  47. {
  48.     vector<int> a={1,3,2,3};
  49.     cout<<findEarlisetMonth(a)<<endl;
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment