I am about to organize a contest for my college on CodeChef via HostYourContest. I want to post the editorials for the same after the contest is over. Is there any guideline or procedure to follow?

You need to post the editorials from your own CodeChef id once the contest is over.

Following are some guidelines that you need to keep in mind while posting the editorials :

# 1. Format :

You need to post the editorials on discuss.codechef.com in wiki markdown.

# 2. Tags :

Tags field is an important field to allow easy searching of the editorial. You need to enter tags for the editorial as follows:

- problem name (eg.
**ak13a**) - problem difficulty (eg. simple)
- contest code (eg.
**alkh2013**) - the word
**editorial** - some relative word from prerequisites section (eg.
**math, factors**,etc)

# 3. Type :

You need to mark the editorial as Community Wiki by clicking on the **community wiki** check box.

# 4. Template :

Template for the Editorial can be found here.

#### You must not miss on reading a very awesome write up on *How to make a good editorial* by Pradeep George Mathias.

I’m trying to upload the editorial of a contest hosted by me. www.codechef.com/QBIT15. It seems I don’t have enough karma to post . What do I do?

CDIYPA01: Editorial

Author: rohit74

Tester :mkmukesh

Editorialist:mkmukesh

Difficulty:

Easy

PREREQUISITES:

Hashing or C++ STL knowledge about Map

PROBLEM

……

Solution:

If you are using simple sorting algorithm for this problem and then solving it for position then your code would take O(nlogn) time but if you want to utilize this problem then you can use map technique of C++ STL from using this technique you can solve this problem in O(n) time complexity. The code is given below that take O(n) time is:

#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main()

{

map<ll int,int> m;

int t,i,n,count;

cin>>t;

while(t–)

{

cin>>n;

ll int ar[n];

count=0;

for(i=0;i<n;i++)

{

cin>>ar[i];

m[ar[i]]=0;

}

map<ll int,int>::iterator p=m.begin();

while(p!=m.end())

{

m[p->first]=++count;

p++;

}

for(i=0;i<n;i++)

cout<<m[ar[i]]<<" ";

cout<<endl;

}

}

CDIYPA02: Editorial

Author: rohit74

Tester :mkmukesh

Editorialist:mkmukesh

Difficulty:

Medium

PREREQUISITES:

Basic knowledge of sorting such as merge and quick sort

PROBLEM

……

Solution:

If you are using simply using loop concept then this problem take O(n^2) time complexity is worst time for finding such difference whose sum is equal to difference of any two elements but you can improve your source code running time complexity if you using merge sort O(nlogn) and binary search O(logn) in worst time. So, your code will take simply O(nlogn) time . the solution is given below:

#include<stdio.h>

void findPair(int [],int ,int);

void merge(int a[], int low, int mid, int high)

{

int b[10000];

int i = low, j = mid + 1, k = 0;

```
while (i <= mid && j <= high) {
if (a[i] <= a[j])
b[k++] = a[i++];
else
b[k++] = a[j++];
}
while (i <= mid)
b[k++] = a[i++];
while (j <= high)
b[k++] = a[j++];
k--;
while (k >= 0) {
a[low + k] = b[k];
k--;
}
```

}

void mergesort(int a[], int low, int high)

{

if (low < high) {

int m = (high + low)/2;

mergesort(a, low, m);

mergesort(a, m + 1, high);

merge(a, low, m, high);

}

}

int main(){

int t;

scanf("%d",&t);

while(t–){

int n;

scanf("%d",&n);

int a[n],i;

for(i=0;i<n;i++){

scanf("%d",&a[i]);

}

int sum=0;

for(i=0;i<n;i++){

int x=a[i];

int m=0,d=0;

while(x!=0){

d=x%10;

if(m<d)

m=d;

x=x/10;

}

sum+=m;

}

mergesort(a,0,n-1);

findPair(a,n,sum);

printf("\n");

}

return 0;

}

void findPair(int arr[], int size, int n)

{

// Initialize positions of two elements

int i = 0;

int j = 1;

```
// Search for a pair
while (i<size && j<size)
{
if (i != j && arr[j]-arr[i] == n)
{
printf("YES");
return;
}
else if (arr[j]-arr[i] < n)
j++;
else
i++;
}
printf("NO");
return;
```

}

CDIYPA03: Editorial

Author: rohit74

Tester :mkmukesh

Editorialist:mkmukesh

Difficulty:

Easy

PREREQUISITES:

basic knowledge of char array and binary number

PROBLEM

……

Solution:

This is quite simple problem in which you have simply take an char array and store remainder of a given number dividing by 2 till the number not gets zero. And finally you get char array in which numbers are in reverse order so, take an temp array in which reverse loop the first array and position the element in temp array from 0th to (n-1)th position. And finally according to given problem situation at position k flip 1 to 0 and 0 to 1. And then convert final binary number into decimal number . in all this process this take O(n) time complexity.

#include

using namespace std;

int main() {

int t;

cin>>t;

while(t–){

unsigned long long int n,k;

cin>>n>>k;

unsigned long long int b=0;

unsigned long long int i=1;

while(n!=0){

```
b=b+i*(n%2);
i=i*10;
n=n/2;
}
unsigned long long int arr[100000],second[100000];
i=0;
while(b!=0){
arr[i]=b%10;
b=b/10;
i++;
}
unsigned long long x=0;
for(int j=i-1;j>=0;j--){
second[x]=arr[j];
x++;
}
if(second[k-1]==0){
second[k-1]=1;
}
else if(second[k-1]==1){
second[k-1]=0;
}
unsigned long long int y=0;
i=1;
for(int j=x-1;j>=0;j--){
y=y+second[j]*i;
i=i*2;
}
cout<<y<<endl;
}
return 0;
```

}

CDIYPA04: Editorial

Author: rohit74

Tester :mkmukesh

Editorialist:mkmukesh

Difficulty:

Medium

PREREQUISITES:

Knowledge about recursion

PROBLEM

……

Solution:

The recursion technique sometimes is most appropriate than the iteration technique. Here according to given problem you have to use a recursive function:

int buff_master(int n,int k){

if(n==1){

return n;

}

else{

return (buff_master(n-1,k)+k-1)%n+1;

}

}