-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpikemaneasy.c
67 lines (49 loc) · 1.1 KB
/
pikemaneasy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "stdlib.h"
#include "stdio.h"
int intcmp(const void* ap, const void* bp) {
long long a = *(long long*)ap;
long long b = *(long long*)bp;
if (a==b)
return 0;
if (a<b)
return -1;
return 1;
}
int N;
long long Tot;
long A;
long B;
long C;
long long T[10000]; // N <= 10^4
int production() {
scanf("%d %lld", &N, &Tot);
scanf("%ld %ld %ld %lld", &A, &B, &C, &T[0] );
for (int i=1; i<N; i++) {
T[i] = (( A*T[i-1] + B ) % C ) + 1;
}
// for (int i=0; i<N; i++)
// printf("%d ", T[i]);
// printf("\n");
// SHBORTING TIME
qsort(T, N, sizeof(long long), intcmp);
int cnt = 0;
long long total_penalty = 0;
long long total_time = 0;
for (; cnt<N; cnt++) {
long long new_time = total_time + T[cnt];
long long new_penalty = (total_penalty + new_time) % 1000000007;
if (new_time > Tot) {
break;
}
total_time = new_time;
total_penalty= new_penalty;
}
// for (int i=0; i<N; i++)
// printf("%d ", T[i]);
// printf("\n");
printf("%d %lld\n", cnt, total_penalty);
return 0;
}
int main() {
return production();
}