forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathK.cpp
More file actions
124 lines (103 loc) · 3.58 KB
/
K.cpp
File metadata and controls
124 lines (103 loc) · 3.58 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;
//Buffer reading
int INP,AM,REACHEOF;
const int BUFSIZE = (1<<12) + 17;
char BUF[BUFSIZE+1], *inp=BUF;
#define GETCHAR(INP) { \
if(!*inp && !REACHEOF) { \
memset(BUF,0,sizeof BUF);\
int inpzzz = fread(BUF,1,BUFSIZE,stdin);\
if (inpzzz != BUFSIZE) REACHEOF = true;\
inp=BUF; \
} \
INP=*inp++; \
}
#define DIG(a) (((a)>='0')&&((a)<='9'))
#define GN(j) { \
AM=0;\
GETCHAR(INP); while(!DIG(INP) && INP!='-') GETCHAR(INP);\
if (INP=='-') {AM=1;GETCHAR(INP);} \
j=INP-'0'; GETCHAR(INP); \
while(DIG(INP)){j=10*j+(INP-'0');GETCHAR(INP);} \
if (AM) j=-j;\
}
//End of buffer reading
struct Problem {
int I, A, L, O;
} problems[111];
struct Team {
int T, Z, V, C;
} teams[111];
struct Result {
int id, ac, penalty;
} res[111];
bool operator < (const Result &a, const Result &b) {
if (a.ac != b.ac) return a.ac > b.ac;
if (a.penalty != b.penalty) return a.penalty < b.penalty;
return a.id < b.id;
}
int m, n, t, l;
pair<int,int> selections[111];
#define TWO(x) (1<<(x))
#define CONTAIN(S,x) (S & TWO(x))
;
inline int up(int a, int b) {
int res = a / b;
if (a % b) ++res;
return res;
}
int main() {
freopen("unfair.in", "r", stdin);
freopen("unfair.out", "w", stdout);
ios :: sync_with_stdio(false);
while (cin >> m >> n >> t >> l) {
FOR(i,1,m) cin >> problems[i].I >> problems[i].A >> problems[i].L >> problems[i].O;
FOR(i,1,t) cin >> teams[i].T >> teams[i].Z >> teams[i].V >> teams[i].C;
int best = t+1, save = -1;
REP(mask,TWO(m)) if (__builtin_popcount(mask) == n) {
// Calculate rank table
FOR(j,1,t) {
res[j].id = j;
int cur = 0;
FOR(i,1,m) if (CONTAIN(mask,i-1))
if (teams[j].T + teams[j].C > problems[i].I - problems[i].O) {
++cur;
int expected = up(problems[i].I, problems[i].O)
+ max(up(problems[i].A, teams[j].C), 5);
int actual = max(problems[i].I - teams[j].T, 0)
+ up(problems[i].A, teams[j].Z + teams[j].C)
+ up(problems[i].L, teams[j].V);
selections[cur] = make_pair(expected, actual);
}
sort(selections+1, selections+cur+1);
int used_time = 0;
res[j].penalty = 0;
res[j].ac = 0;
FOR(i,1,cur)
if (used_time + selections[i].second <= l) {
used_time += selections[i].second;
res[j].ac++;
res[j].penalty += used_time;
}
else break;
}
sort(res+1, res+t+1);
int cur = 0;
FOR(i,1,t) if (res[i].id == 1) cur = i;
if (cur < best) {
best = cur;
save = mask;
}
}
FOR(i,1,m) if (CONTAIN(save,i-1)) cout << i << ' ';
cout << endl;
}
return 0;
}