Created
July 18, 2014 13:13
-
-
Save cocodrips/f21f73fd03ac64af92aa to your computer and use it in GitHub Desktop.
SRM624 Div1 Easy in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
#include <cstring> | |
#include <ctime> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
#include <vector> | |
#include <sstream> | |
#include <typeinfo> | |
#include <fstream> | |
using namespace std; | |
class BuildingHeights { | |
public: | |
int minimum(vector<int> heights) { | |
int N = heights.size(); | |
sort(heights.begin(), heights.end()); | |
int sums[heights.size() + 1]; | |
sums[0] = 0; | |
for (int i = 0; i < N; ++i){ | |
sums[i+1] = sums[i] + heights[i]; | |
} | |
int result = 0; | |
for (int n = 2; n <= N; ++n){ | |
int mini = 2147483647; //INT_MAXにしたい | |
for (int l = 0; l <= N - n; ++l){ | |
mini = min(mini, heights[l + n - 1] * n - (sums[l + n] - sums[l])); | |
} | |
result ^= mini; | |
} | |
return result; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment