Created
November 21, 2016 01:18
-
-
Save jianminchen/8a448bac7de8ad3667b125abe3544e5d to your computer and use it in GitHub Desktop.
Minimum Cost - woman codesprint #2 - study code C++ - 30 lines of code - simplicity
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 <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
using namespace std; | |
int main() { | |
set<long long> pass; | |
int n; | |
cin >> n; | |
long long best = 100000000000000000ll; | |
for(int i = 0; i < n; i++){ | |
long long int p; | |
cin >> p; | |
auto j = pass.upper_bound(p); | |
if(j != pass.end()){ | |
auto d = *j - p; | |
best = min(best, d); | |
} | |
pass.insert(p); | |
} | |
cout << best << '\n'; | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment