#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(), rendez);
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 | 1812 KiB | ||||
2 | Accepted | 3ms | 2004 KiB | ||||
subtask2 | 0/13 | ||||||
3 | Accepted | 2ms | 2088 KiB | ||||
4 | Wrong answer | 3ms | 2212 KiB | ||||
5 | Wrong answer | 3ms | 2432 KiB | ||||
6 | Wrong answer | 3ms | 2636 KiB | ||||
subtask3 | 0/22 | ||||||
7 | Wrong answer | 3ms | 2884 KiB | ||||
8 | Wrong answer | 3ms | 3096 KiB | ||||
9 | Wrong answer | 3ms | 3180 KiB | ||||
10 | Accepted | 3ms | 3432 KiB | ||||
11 | Accepted | 3ms | 3676 KiB | ||||
12 | Wrong answer | 3ms | 3764 KiB | ||||
13 | Wrong answer | 3ms | 3724 KiB | ||||
14 | Wrong answer | 3ms | 3728 KiB | ||||
subtask4 | 0/65 | ||||||
15 | Time limit exceeded | 1.1s | 4608 KiB | ||||
16 | Wrong answer | 310ms | 6940 KiB | ||||
17 | Time limit exceeded | 1.052s | 4816 KiB | ||||
18 | Wrong answer | 85ms | 6872 KiB | ||||
19 | Wrong answer | 85ms | 6792 KiB | ||||
20 | Wrong answer | 83ms | 6796 KiB | ||||
21 | Wrong answer | 85ms | 6792 KiB | ||||
22 | Wrong answer | 83ms | 7148 KiB | ||||
23 | Wrong answer | 81ms | 7016 KiB | ||||
24 | Wrong answer | 82ms | 7004 KiB |