1 solutions

  • 0
    @ 2023-12-3 20:54:37

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        
        int N;
        cin >> N;
        vector<int> p(N + 1), t(N + 1), d(N + 2);
        for (int i = 1; i <= N; ++i)
            cin >> p[i];
        for (int i = 1; i <= N; ++i)
            cin >> t[i];
        for (int i = 1; i <= N; ++i)
            d[i] = p[i] - t[i];
        int ans = 0;
        for (int i = 0; i <= N; ++i)
            ans += abs(d[i] - d[i + 1]);
        cout << ans / 2;
        return 0;
    }
    
    • 1

    USACO 2021 December Contest&#44; Bronze —— T2:Air Cownditioning

    Information

    ID
    1299
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    (None)
    Tags
    (None)
    # Submissions
    0
    Accepted
    0
    Uploaded By