What is good approach to merge sorted files. I have around 10k files of size 1-2 mb and want to merge them in single sorted file.

# | User | Rating |
---|---|---|

1 | tourist | 3438 |

2 | moejy0viiiiiv | 3288 |

3 | W4yneb0t | 3218 |

4 | LHiC | 3196 |

5 | TakanashiRikka | 3178 |

6 | Petr | 3163 |

7 | Um_nik | 3150 |

8 | izrak | 3109 |

9 | ershov.stanislav | 3105 |

10 | mnbvmar | 3018 |

# | User | Contrib. |
---|---|---|

1 | rng_58 | 179 |

2 | csacademy | 171 |

2 | tourist | 171 |

4 | Petr | 162 |

5 | Swistakk | 158 |

6 | Errichto | 156 |

7 | Zlobober | 152 |

7 | matthew99 | 152 |

9 | zscoder | 139 |

10 | Endagorion | 138 |

can anyone suggest me a good source , i know about "spoj" but read some bad review about it on quora

Is spoj good to learn different approach and algorithms ?

If any other source helped you than please tell.I don't want to waste time on adhoc problems.

Note: I know that many people ask such question and i read them also but still i have doubts so posted

In this problem you are given "x" amount of money in currency "s" and you want to maximise the amount in "m" steps to currency "f". cost matrix is given for transfer rate. Sounds similar to finding number of ways to reach from one node to another in k steps. So the answer to problem is (s,f) value of mth power of given cost matrix (exchange rate matrix). we need to modify matrix multiplication accordingly to get maximum cost.

```
matrix matmul(matrix &a,matrix &b)
{
int n=a.size();
ll temp;
matrix ans(n,vector<ll>(n));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
temp=0;
for(int k=0;k<n;k++)
{
temp=max(temp,a[i][k]*b[k][j]) %mod; // this is problem
}
ans[i][j]=temp;
}
}
return ans;
}
```

But we want ans%mod , this mod will ruin my multiplication of matrix. I will not get maximum. Editorial suggest to use power of primes , can someone please explain that.

Problem Link

a) It does not have leading "X" letter.

b) It does not contain P consecutive "X" letters.

`N<10^4 and P<11`

I am unable to form recurrence of this dp problem. can someone please explain the recurrence in an easy way.

I was thinking about dp[i][j] as number of strings of length i ending with j 'X' , but not able to come up with transition.

Thanks.

Problem Statement :

You are given an array A of N integers in nondecreasing order. Remove K integers such that the maximum difference between two consecutive elements is minimized.

Problem Link

solution using binary search (I am not getting its intuition).

Today i was solving Ktree and i came with this solution. This solution gave me TLE. This is most obvious solution which anyone can think and code. Now i don't see any repetitive states in this solution to memoize .Am i missing something ? Or if i am going wrong then please tell your recursive approach.

```
#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
const int mod = 1e9+7;
typedef long long ll;
#define mp make_pair
#define pb push_back
ll n,k,d;
ll solve(ll sum,ll seen)
{
if(sum==n and seen==1)
return 1;
if(sum>n or (sum==n and !seen) )
return 0;
ll ans=0;
for(int i=1;i<=k;i++)
{
if(i>=d)
seen=1;
ans+=solve(sum+i,seen);
}
return ans;
}
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
// freopen ("inp","r",stdin);
// freopen ("out","w",stdout);
cin>>n>>k>>d;
cout<<solve(0,0);
return 0;
}
```

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/21/2017 15:21:22 (p1).

Desktop version, switch to mobile version.

User lists

Name |
---|