Submission #947223

# Submission time Handle Problem Language Result Execution time Memory
947223 2024-03-15T17:49:26 Z devkudawla Walking (NOI12_walking) C++17
0 / 25
1 ms 1372 KB
#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][j] = max(dp[i][j], 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 time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -