## Saturday, July 30, 2011

### SRM195

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

## Tutorials:

### Solution

The same with Div2 Level2.

### Solution

Follow the tutorials from TC, and use greedy algorithms to implement.

### Source Code:

//Sat Jul 30 17:46:03 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 FanFailure {
public:
vector <int> getRange(vector <int>, int);
};

vector <int> FanFailure::getRange(vector <int> cap, int minC) {
int N = cap.size();
sort(cap.begin(), cap.end());
vector<int> ret(2, 0);
ret[0] = 0;
ret[1] = N;

for(int i=0; i<=N; i++){
int sum1 = 0;
int sum2 = 0;
for(int j=0; j<N; j++) if(j>=i) sum1 += cap[j];
for(int j=0; j<N; j++) if(j<N-i) sum2 += cap[j];
if(sum1 >= minC) ret[0] = max(ret[0], i);
if(sum2 < minC) ret[1] = min(ret[1], i-1);
}
return ret;
}