int maxSongs(vector <int> duration, vector <int> tone, int T) { IIVec v; int N = (int)tone.size(); int i, j, k; for (i = 0; i < N; ++i) { v.push_back(II(tone[i], duration[i])); } sort(v.begin(), v.end()); #define INF 0x3f3f3f3f int dp[64][64] = {}; memset(dp, 0x3f, sizeof(dp)); for (i = 0; i < N; ++i) { for (j = 0; j < i; ++j) { for (k = 1; k <= i; ++k) { dp[i][k+1] = min(dp[i][k+1], dp[j][k] + v[i].first-v[j].first + v[i].second); } } dp[i][1] = v[i].second; } int ans = 0; for (k = 1; k <= N; ++k) { for (i = 0; i < N; ++i) { if (dp[i][k] <= T) { ans = k; } } } return ans; }
int maxSongs(vector <int> duration, vector <int> tone, int T) { int ans = 0; IIVec v; for (int i = 0; i < (int)tone.size(); ++i) { v.push_back(II(tone[i], duration[i])); } sort(v.begin(), v.end()); int dp[64][64]; memset(dp, 0x3f, sizeof(dp)); for (int i = 0; i < (int)v.size(); ++i) { for (int j = 0; j < i; ++j) { for (int k = 1; k <= i; ++k) { dp[i][k + 1] = min(dp[i][k + 1], dp[j][k] + abs(v[i].first - v[j].first) + v[i].second); if (dp[i][k + 1] <= T) { ans = max(ans, k + 1); } } } dp[i][1] = v[i].second; if (v[i].second <= T) { ans = max(ans, 1); } } return ans; }
double maxExpectation(int M, vector <int> day, vector <int> win, vector <int> gain) { Max = M; IIVec Days; int i; for (i = 0; i < (int)day.size(); ++i) { if (win[i] > 0 && gain[i] > 0) { Days.push_back(II(day[i], i)); } } sort(Days.begin(), Days.end()); _day.clear(); _win.clear(); _gain.clear(); memset(memo, 0, sizeof(memo)); for (i = 0; i < (int)Days.size(); ++i) { _day.push_back(Days[i].first); _win.push_back(win[Days[i].second] * 0.01); _gain.push_back(gain[Days[i].second]); } if (Days.size() <= 0 || M <= _day[0]) { return M; } return rec(0, M - _day[0]); }
vector <int> minimalDifference(vector <int> h) { int N = (int)h.size(); IIVec v; for (int i = 0; i < N; ++i) { v.push_back(II(h[i], i)); } sort(v.begin(), v.end()); vector <int> ans(N); int l = 0, r = N - 1; for (int i = 0; i < N; ++i) { if (i % 2) { ans[r--] = v[i].second; } else { ans[l++] = v[i].second; } } return ans; }
int main(int argc, char *argv[]) { IIVec v; int N; cin >> N; for (int i = 0; i < N; ++i) { int a; cin >> a; v.push_back(II(a, i)); } sort(v.begin(), v.end()); int ans = 0; for (int i = 0; i < N; ++i) { ans += (i % 2) != (v[i].second % 2); } cout << ans / 2 << endl; return 0; }
vector <int> construct(vector <int> x) { IIVec v; for (int i = 0; i != x.size(); ++i) { v.push_back(II(x[i], i)); } sort(v.begin(), v.end()); vector <int> ans; for (int i = 0; i != v.size(); ++i) { if (v[i].first > (i + 1)) { ans.resize(1); ans[0] = -1; break; } for (int j = 0; j < (v[i].first - 1); ++j) { ans.push_back(v[i].second); ans.push_back(v[j].second); } } return ans; }