#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 | Runtime error | 3ms | 1840 KiB | ||||
2 | Runtime error | 3ms | 2116 KiB | ||||
subtask2 | 0/13 | ||||||
3 | Runtime error | 3ms | 2312 KiB | ||||
4 | Runtime error | 3ms | 2676 KiB | ||||
5 | Runtime error | 3ms | 2700 KiB | ||||
6 | Runtime error | 3ms | 2836 KiB | ||||
subtask3 | 0/22 | ||||||
7 | Runtime error | 3ms | 3120 KiB | ||||
8 | Runtime error | 3ms | 3148 KiB | ||||
9 | Runtime error | 3ms | 3156 KiB | ||||
10 | Runtime error | 3ms | 3340 KiB | ||||
11 | Runtime error | 3ms | 3208 KiB | ||||
12 | Runtime error | 3ms | 3488 KiB | ||||
13 | Runtime error | 3ms | 3760 KiB | ||||
14 | Runtime error | 3ms | 3768 KiB | ||||
subtask4 | 0/65 | ||||||
15 | Runtime error | 3ms | 3820 KiB | ||||
16 | Runtime error | 3ms | 3820 KiB | ||||
17 | Runtime error | 3ms | 4068 KiB | ||||
18 | Runtime error | 3ms | 4096 KiB | ||||
19 | Runtime error | 3ms | 4124 KiB | ||||
20 | Runtime error | 3ms | 4220 KiB | ||||
21 | Runtime error | 3ms | 4436 KiB | ||||
22 | Runtime error | 3ms | 4384 KiB | ||||
23 | Runtime error | 3ms | 4388 KiB | ||||
24 | Runtime error | 3ms | 4384 KiB |