Created
June 28, 2014 06:57
-
-
Save KPCCoiL/eb3c275bdd4bf3658ca2 to your computer and use it in GitHub Desktop.
This file contains 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 <algorithm> | |
#include <vector> | |
using namespace std; | |
class BuildingHeights { | |
public: | |
int minimum(vector <int> heights) { | |
const int N = heights.size(); | |
sort(heights.begin(),heights.end()); | |
vector<int> accum(N); | |
accum[0] = heights[0]; | |
for (int i = 1; i < N; i++) | |
accum[i] = accum[i-1]+heights[i]; | |
int ans = 0; | |
for (int i = 2; i <= N; i++) { | |
int now = 1e9; | |
for (int j = 0; i+j-1 < N; j++) | |
now = min(now,heights[j+i-1]*i-(accum[j+i-1]-(j?accum[j-1]:0))); | |
ans ^= now; | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment