Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <set>
- #include <string>
- #include <stdio.h>
- #include <sstream>
- #include <iomanip>
- using namespace std;
- using ll = long long;
- vector <int> h;
- int cl(int i, int j) {
- if (!(i >= 0 && i < (int)h.size() && j >= 0 && j < (int)h.size())) {
- return 666;
- }
- else return abs(i - j) + h[j] - h[i];
- //return abs(i - j) + h[j] - h[i];
- }
- void co(vector <int> v) {
- for (auto& x : v) cout << x << ' ';
- cout << '\n';
- }
- int N;
- int cnt(vector <int> v) {
- int res = 0;
- for (int i = 0; i < N - 1; ++i) {
- int pl = cl(v[i], v[i + 1]);
- if (pl == 666) {
- cout << "BUG BAD INDEX\n";
- cout << "v[i] = " << v[i] << " v[i+1] = " << v[i+1]<<"\n";
- if (v[i] >= 0 && v[i] < (int)v.size()){
- cout<<"high = "<<h[v[i]]<<'\n';
- }
- //cout<<"h[v[i]] = "<<h[v[i]]<<" h[v[i+1]] = "<<h[v[i+1]]<<'\n';
- }
- res += pl;
- }
- return res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n;
- cin >> n;
- N = n;
- vector <int> h;
- h.resize(n);
- vector <int> v;
- cout << "size h = " << h.size() << '\n';
- for (int i = 0; i < n; ++i) {
- cin >> h[i];
- v.push_back(i);
- }
- co(h);
- int max = -100;
- int tot = -99;
- vector <int> be;
- do {
- tot = cnt(v);
- co(v);
- //cout << tot << '\n'<<'\n';
- if (tot > max) {
- //cout << tot << '\n';
- be = v;
- max = tot;
- }//cout << '\n';
- } while (next_permutation(v.begin(), v.end()));
- cout << max << '\n';
- //cout << "b\n";
- //co(be);
- //ch(b);
- }
Add Comment
Please, Sign In to add comment