## Friday, July 29, 2011

### SRM204

Level 1 Level 2 Level 3
Div 1 Level 1 Level 2 Level 3
Div 2 Level 1 Level 2 Level 3

## Tutorials:

### Solution

Follow the tutorials from TC, and source code of SnapDragon.

### Source Code:

//Fri Jul 29 21:37:31 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class WorldPeace {
public:
long long numGroups(int, vector <int>);
};

long long WorldPeace::numGroups(int k, vector <int> c) {
long long hi = 10000000000000000LL;
long long lo = 0LL;
while(hi > lo){
long long mid = (hi + lo + 1) / 2;
long long sum = 0LL;
for(int i=0; i<c.size(); i++){
sum += c[i]<mid ? c[i]:mid;
}
if(sum < mid * k) hi = mid-1;
else lo = mid;
}
return hi;
}

### Source Code:

//2009/08/13 18:26:45
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class Medici
{
public:
int winner(vector <int> fame, vector <int> fortune, vector <int> secrets)
{
int ret = -1;
int mmax = -1;
bool ties = false;
for(int i=0; i<fame.size(); i++)
{
int mmin = min(fame[i], min(fortune[i], secrets[i]));
if(mmin > mmax)
{
mmax = mmin;
ties = false;
ret = i;
}
else if(mmin == mmax) ties = true;
}
if(ties) ret = -1;
return ret;
}
};