#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 <= sz2.sebzes);
}
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(), 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 | 1816 KiB | ||||
2 | Wrong answer | 3ms | 2180 KiB | ||||
subtask2 | 0/13 | ||||||
3 | Wrong answer | 3ms | 2160 KiB | ||||
4 | Wrong answer | 3ms | 2296 KiB | ||||
5 | Wrong answer | 3ms | 2380 KiB | ||||
6 | Wrong answer | 3ms | 2620 KiB | ||||
subtask3 | 0/22 | ||||||
7 | Wrong answer | 3ms | 2848 KiB | ||||
8 | Wrong answer | 3ms | 2944 KiB | ||||
9 | Wrong answer | 2ms | 3024 KiB | ||||
10 | Wrong answer | 3ms | 3156 KiB | ||||
11 | Wrong answer | 3ms | 3236 KiB | ||||
12 | Wrong answer | 3ms | 3244 KiB | ||||
13 | Wrong answer | 2ms | 3240 KiB | ||||
14 | Wrong answer | 3ms | 3480 KiB | ||||
subtask4 | 0/65 | ||||||
15 | Runtime error | 61ms | 6780 KiB | ||||
16 | Runtime error | 108ms | 6856 KiB | ||||
17 | Runtime error | 70ms | 6916 KiB | ||||
18 | Wrong answer | 85ms | 6968 KiB | ||||
19 | Wrong answer | 85ms | 6928 KiB | ||||
20 | Wrong answer | 83ms | 7004 KiB | ||||
21 | Wrong answer | 85ms | 7256 KiB | ||||
22 | Wrong answer | 85ms | 7216 KiB | ||||
23 | Wrong answer | 82ms | 7296 KiB | ||||
24 | Wrong answer | 82ms | 7200 KiB |