Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Friday, October 17, 2014

PRATA - Roti Prata

Roti Prata

Given below code is for prata spoj or roti prata spoj.

Hint :-> Use Binary Search 

This problem can also be solved by BFS also but i don't know how to solve it using bfs/dfs if any one know it then please comment of mail me your approach @

#include <bits/stdc++.h>
using namespace std;
#define ULL unsigned long long 
int n;
ULL get_num(int a,ULL sum)
    ULL d = (ULL)sqrt(a*a + 8*a*sum);
    return d / (2*a);
int check(int arr[],ULL chef,ULL tim)
    ULL count = 0;
    for(ULL i =0 ;i<chef;i++)
        count += get_num(arr[i],tim);
        if(count >= n)
            return 1;
    return 0;
ULL binary_search(int arr[],ULL chef,ULL max)
    ULL low = 1,mid,high = max;
        mid = (low+high)>>1;
            high = mid;
            low = mid + 1;
    return low;
int main()
    int t;
        int chef;
        int arr[chef+9],ma = -1;
        for(int i = 0;i<chef ; i++){
        ULL res = binary_search(arr,chef,(ULL)10*n*(n+1)/2);
    return 0;