This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll n;
cin >> n;
pair<ll,ll>p[n+2];
for (ll i=1; i<=n; i++) {
cin >> p[i].first >> p[i].second;
}
sort(p+1,p+n+1);
ll pref[n+4];
memset(pref,0,sizeof(pref));
for (ll i=1; i<=n; i++) {
pref[i]=pref[i-1]+p[i].second;
}
ll ans=0;
for (ll i=1; i<n; i++) {
for (ll j=i+1; j<=n; j+=i) {
ans=max(ans,(pref[j]-pref[i-1])-p[j].first+p[i].first);
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |