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<iostream>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;
int wynik[300000];
vector<pair<int,int> > Q;
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,m,x,y;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>x>>y;
Q.push_back({y,x});
}
sort(Q.begin(),Q.end());
int suma=0;
int wynikk=0;
for(int i=0;i<n;i++)
{
suma+=Q[i].second;
if(i+1<m)
{
wynik[i]=-suma+Q[i].second+2*Q[i].first;
continue;
}
wynikk=max(wynikk,suma-2*Q[i].first+wynik[i-m+1]);
wynik[i]=-suma+Q[i].second+2*Q[i].first;
}
cout<<wynikk;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |