Submission #986589

# Submission time Handle Problem Language Result Execution time Memory
986589 2024-05-20T20:31:29 Z AverageAmogusEnjoyer Sails (IOI07_sails) C++17
25 / 100
1000 ms 2908 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> bool cmin(T &i,T j) { return i > j ? i = j,true: false; }
template<class T> bool cmax(T &i,T j) { return i < j ? i = j,true: false; }

constexpr int nax = 100100;
ll a[nax];
ll b[nax];
int n;

ll solve(ll k) {
    copy(a,a+nax,b);
    ll ans = 0;
    for (int i=nax-1;i>=1;i--) {
        ll to_do = min(k,b[i]);
        ans += to_do*(to_do-1)/2;
        b[i]-=to_do;
        b[i-1]+=b[i];
    }
    if (b[0] != 0) { return 1LL<<60; }
    return ans;
}

void solve() {
    cin >> n;
    ll sum = 0;
    for (int i=0,h,k;i<n;i++) {
        cin >> h >> k;
        a[h]++;
        a[h-k]--;
        sum += k;
    }
    for (int i=nax-1;i>=1;i--) { a[i-1]+=a[i]; }
    ll ans = 1LL<<60;
    for (ll s = 0; s <= sum; s++) {
        cmin(ans,solve(s));
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1880 KB Output is correct
2 Correct 5 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1884 KB Output is correct
2 Correct 5 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1884 KB Output is correct
2 Correct 7 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 1884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1036 ms 1880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 1884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 2140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 2396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1044 ms 2768 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1020 ms 2904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 2908 KB Time limit exceeded
2 Halted 0 ms 0 KB -