Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created November 21, 2016 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/8a448bac7de8ad3667b125abe3544e5d to your computer and use it in GitHub Desktop.
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
#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