Invitation to CodeChef Starters 109 (Rated till 5-stars) - 22nd November

We invite you to participate in CodeChef’s Starters 109, this Wednesday, 22nd November, rated till 5-stars (ie. for users with rating < 2200).

Time: 8:00 PM — 10:00 PM IST

Read about the recent judge migration here.

Joining us on the problem setting panel are:

Written editorials will be available for all on discuss.codechef.com. Pro users can find the editorials directly on the problem pages after the contest. The video editorials of the problems will be available only to Pro users.

Also, if you have some original and engaging problem ideas, and you’re interested in them being used in CodeChef’s contests, you can share them here.

Hope to see you participating.

Good Luck!

2 Likes

Can you please tell me why my code didnt work for this problem ? Thank you
here is the question link ALT Problem - CodeChef

my code include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {

int t;
cin>>t;
while(t--)
{
    ll n;
    cin>>n;
    
    vector<ll> A(n);
    
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
    }
    
    
    sort(A.begin(),A.end());
   
    vector<int> v;
    
    for(int i=0; i<n/2; i++)
    {
        ll sum =A[i]+A[n-1-i];
        ll diff=abs(A[i]-A[n-1-i]);
        
        v.push_back(sum/2);
        v.push_back(diff/2);
        
    }
    
    ll sum=0;
    
    for(int i=n/2; i<n; i++)
    {
        sum+=A[i];
    }
    
    ll tum=0;
    for(auto it:v)
    {
        tum+=it;
    }
    
    if(sum==tum)
    {
        
    for(auto it:v)
    cout<<it<<" ";
    cout<<endl;
    
    }
    else
    cout<<-1<<endl;
    
}

return 0;

}

the test case it showed me wrong result upon

Can anyone clarify my doubt. I currently 1 star coder my rating before starters 109 was 1190. During the contest I have attempted 3 questions. Solved them correctly and submitted. I did not submit any kind of wrong solution. Still my rating decreased by 25. Why???

Hey guys, I am trying to solve the Alter Ego problem which comes in starter 109
My approach: I am trying to take elements by using lower_bound , and delete it if conditions are satisfied and move forward
I don’t know why code is not working well can anyone help me to give the test cases in which my code is failing or help me to correct the approach
Here is my code:
// Nobita_Nobi Copyright 2023-2024 the only code by Nobita_Nobi
// i am happy that you will learn something new from my solution

include <bits/stdc++.h>
include
using namespace std;
define fast ios_base::sync_with_stdio(false);
define input cin.tie(NULL);
define ll long long
// include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// define pii pair<int,int>
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash {
// int operator()(int x) const { return x ^ RANDOM; }
// };

// gp_hash_table<int, int, chash> mp; // unordered_map

void solve()
{
ll n;
cin>>n;
ll a[n],b[n],cola[n],colb[n];
vector<multiset>col(2*n+1);
map<ll,vector>mp;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
ll k;
cin>>k;
cola[i]=k;
mp[k].push_back(a[i]);
}
for(int i=0;i<n;i++) cin>>b[i];

for(int i=0;i<n;i++){
	ll k;
	cin>>k;
	mp[k].push_back(b[i]);
	colb[i]=k;
}
for(auto it:mp){
	ll k=it.first;
	vector<ll>v=it.second;
	multiset<ll>tmp;
	for(auto num:v) tmp.insert(num);
	col[k]=tmp;
}
ll last=-1;
for(int i=0;i<n;i++){
	ll pos=cola[i];
	auto check=col[pos].lower_bound(last);
	if(check==col[pos].end()){
		cout<<"NO\n";
		return;
	}
	ll val=*check;
	if(val<last){
		cout<<"NO\n";
		return;
	}
	col[pos].erase(check);
	last=val;
}
cout<<"YES\n";

}

int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif

fast input
int t;
cin>>t;
while(t--) 
solve();

return 0;

}

Your rating before the contest was 1190, but you were unable to solve the fourth problem which had a rating of 1154. So it’s easy to see why your rating fell down.