Submission #947224

#TimeUsernameProblemLanguageResultExecution timeMemory
947224devkudawlaWalking (NOI12_walking)C++17
10 / 25
2 ms1368 KiB
#include <bits/stdc++.h> using namespace std; void solve(bool testCases = true) { int T = 1; if (testCases) cin >> T; while (T--) { int l, n; cin >> l >> n; vector<pair<int, pair<int, int>>> v(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v[i] = {i, {a, b}}; } sort(begin(v), end(v), [&](pair<int, pair<int, int>> &a, pair<int, pair<int, int>> &b) { return a.second.first < b.second.first; }); vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0)); v.insert(begin(v), {-1, {0, INT_MAX}}); for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { dp[i][j] = dp[i - 1][j]; } for (int j = 0; j <= i - 1; j++) { int tj = v[j].second.first, vj = v[j].second.second; int ti = v[i].second.first, vi = v[i].second.second; long long int left = vj * (l + ti * vi); long long int right = vi * (l + tj * vj); if (right > left) { dp[i][i] = max(dp[i][i], 1 + dp[i - 1][j]); } } } int answer = 0; for (int i = 0; i <= n; i++) { answer = max(answer, dp[n][i]); } cout << answer; cout << "\n"; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(false); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...