题意:邮递员送快递,有容量限制,贪心取远的先。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
struct node {
ll x;
ll m;
};
bool cmp(node a,node b) {
return a.x<b.x;
}
int main() {
vector<node> a(1500),b(1500);
cin>>n>>k;
ll c,d;
while(n--) {
cin>>c>>d;
if(c>0)
a.push_back((node) {
c,d
});
if(c==0)
continue;
if(c<0)
b.push_back((node) {
-c,d
});
}
sort(a.begin(),a.end(),cmp);
sort(b.begin(),b.end(),cmp);
ll ans = 0;
ll tmp = 0;
ll i = a.size()-1;
while(i>=0) {
ans += a[i].m/k*a[i].x*2;
if(a[i].m%k) {
int s = k-a[