#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);
for(int i = 1; i <= n; i++){
cout << sz[i].elet << " " << sz[i].sebzes << "\n";
}
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 | Wrong answer | 3ms | 1816 KiB | ||||
2 | Wrong answer | 3ms | 2140 KiB | ||||
subtask2 | 0/13 | ||||||
3 | Wrong answer | 3ms | 2224 KiB | ||||
4 | Wrong answer | 3ms | 2468 KiB | ||||
5 | Wrong answer | 3ms | 2680 KiB | ||||
6 | Wrong answer | 3ms | 2584 KiB | ||||
subtask3 | 0/22 | ||||||
7 | Wrong answer | 3ms | 2952 KiB | ||||
8 | Wrong answer | 3ms | 2984 KiB | ||||
9 | Wrong answer | 3ms | 2808 KiB | ||||
10 | Wrong answer | 3ms | 3044 KiB | ||||
11 | Wrong answer | 2ms | 3132 KiB | ||||
12 | Wrong answer | 3ms | 3276 KiB | ||||
13 | Wrong answer | 3ms | 3328 KiB | ||||
14 | Wrong answer | 3ms | 3428 KiB | ||||
subtask4 | 0/65 | ||||||
15 | Time limit exceeded | 1.1s | 4392 KiB | ||||
16 | Wrong answer | 333ms | 6588 KiB | ||||
17 | Time limit exceeded | 1.065s | 4504 KiB | ||||
18 | Wrong answer | 107ms | 6760 KiB | ||||
19 | Wrong answer | 107ms | 6696 KiB | ||||
20 | Wrong answer | 108ms | 6764 KiB | ||||
21 | Wrong answer | 107ms | 6892 KiB | ||||
22 | Wrong answer | 107ms | 7084 KiB | ||||
23 | Wrong answer | 104ms | 6872 KiB | ||||
24 | Wrong answer | 104ms | 6964 KiB |