Submission #669335

#TimeUsernameProblemLanguageResultExecution timeMemory
669335raypeng1729Sails (IOI07_sails)C++17
45 / 100
25 ms3776 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) v.begin(), v.end() const int N = 1e4, INF = 1e9 + 1, MOD = 1e9 + 7, K = __lg(N) + 1; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n], b[n], mx = 0; for(int i = 0; i < n; i++) cin >> a[i] >> b[i], mx = max(mx, a[i]); int pre[mx + 2]{}; for(int i = 0; i < n; i++){ pre[0]++, pre[a[i] + 1]--; } for(int i = 1; i <= mx; i++) pre[i] += pre[i - 1]; int ans = 0, cnt = accumulate(b, b + n, 0); for(int i = mx; i > 0; i--){ int cur = min(pre[i], cnt / i); ans += cur * (cur - 1) / 2; cnt -= cur; } cout << ans; }
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...