From 771ba7f813625e8a15bcc4045f956e96d6bfec54 Mon Sep 17 00:00:00 2001 From: ShazidMahsrafi Date: Tue, 25 Jun 2024 04:30:45 +0600 Subject: [PATCH] feat: Add solution for Codeforces problem 1986E --- Codes/1986 E - Beautiful Array/1986E.cpp | 84 ++++++++++++++++++++++++ Readme.md | 1 + 2 files changed, 85 insertions(+) create mode 100644 Codes/1986 E - Beautiful Array/1986E.cpp diff --git a/Codes/1986 E - Beautiful Array/1986E.cpp b/Codes/1986 E - Beautiful Array/1986E.cpp new file mode 100644 index 0000000..f0d6347 --- /dev/null +++ b/Codes/1986 E - Beautiful Array/1986E.cpp @@ -0,0 +1,84 @@ +#include +using namespace std; +#ifdef ONLINE_JUDGE +#define dbg(...) +#else +#include "Assets/debug.h" +#endif +#define int long long +#define ll long long +#define endl '\n' +#define all(x) x.begin(), x.end() +#define sz(x) (int)(x).size() +#define yes cout << "YES" << endl +#define no cout << "NO" << endl +#define rep(i,a,b) for(int i=a; i=b; --i) +#define pb push_back +#define ppb pop_back +#define ins insert +#define ff first +#define ss second +#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr)); +ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} + +void solve() +{ + int n,k; + cin>>n>>k; + map>m; + rep(i,0,n) + { + int x; + cin>>x; + m[x%k].pb(x/k); + } + int odd=n&1, ans=0; + for(auto it:m) + { + vector&v=it.second; + int len = sz(v); + sort(all(v)); + if(len&1) + { + if(!odd) + { + cout<<-1<pf(len,0),sf(len,0); + pf[1]=v[1]-v[0]; + sf[len-2]=v[len-1]-v[len-2]; + for(int i=3; i=0; i-=2) sf[i]=sf[i+2]+v[i+1]-v[i]; + int mn=INT_MAX; + for(int i=0; i0) sum+=pf[i-1]; + if(i> TCS; + for (int TC = 1; TC <= TCS; ++TC) + { + // cout<<"Case "<