#include <bits/stdc++.h>
using namespace std;
struct Szorny{
long long int elet, sebzes;
};
bool rendez(Szorny sz1, Szorny sz2){
double x1 = double(sz1.sebzes) / double(sz1.elet);
double x2 = double(sz2.sebzes) / double(sz2.elet);
return (x1 >= x2);
}
bool rendez1(Szorny sz1, Szorny sz2){
return (sz1.sebzes - sz1.elet >= sz2.sebzes - sz2.elet);
}
int main()
{
//ifstream cin("elod.txt");
long long int n, p, sum = 0, index = 1, megoldas = 0;
cin >> n >> p;
vector<Szorny> sz(n + 1);
for(long long int i = 1; i <= n; i++){
cin >> sz[i].elet >> sz[i].sebzes;
sum += sz[i].sebzes;
}
sort(sz.begin() + 1, sz.end(), rendez1);
sz[1].elet -= p;
if(sz[1].elet <= 0){
index++;
sum -= sz[1].sebzes;
}
while(index != n + 1){
megoldas += ceil(sz[index].elet / p) * sum;
sum -= sz[index].sebzes;
index++;
}
cout << megoldas;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1844 KiB | ||||
2 | Wrong answer | 3ms | 2096 KiB | ||||
subtask2 | 0/13 | ||||||
3 | Wrong answer | 3ms | 2212 KiB | ||||
4 | Wrong answer | 2ms | 2304 KiB | ||||
5 | Wrong answer | 3ms | 2428 KiB | ||||
6 | Wrong answer | 3ms | 2788 KiB | ||||
subtask3 | 0/22 | ||||||
7 | Runtime error | 3ms | 2912 KiB | ||||
8 | Wrong answer | 3ms | 3140 KiB | ||||
9 | Runtime error | 3ms | 3340 KiB | ||||
10 | Wrong answer | 3ms | 3296 KiB | ||||
11 | Wrong answer | 3ms | 3408 KiB | ||||
12 | Wrong answer | 3ms | 3596 KiB | ||||
13 | Wrong answer | 3ms | 3820 KiB | ||||
14 | Wrong answer | 3ms | 3908 KiB | ||||
subtask4 | 0/65 | ||||||
15 | Runtime error | 59ms | 7188 KiB | ||||
16 | Runtime error | 52ms | 7324 KiB | ||||
17 | Runtime error | 70ms | 7540 KiB | ||||
18 | Wrong answer | 78ms | 7120 KiB | ||||
19 | Wrong answer | 76ms | 7204 KiB | ||||
20 | Wrong answer | 75ms | 7200 KiB | ||||
21 | Wrong answer | 76ms | 7316 KiB | ||||
22 | Wrong answer | 75ms | 7524 KiB | ||||
23 | Wrong answer | 112ms | 7676 KiB | ||||
24 | Wrong answer | 109ms | 7784 KiB |