Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- struct T {
- int a, c, n;
- } t[610];
- bool cmpT(T a, T b) {
- return a.c < b.c;
- }
- int n, k, p, b[610], d[610][610], f[610][610], r;
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- for (int i = 0; i < 610; i++)
- for (int j = 0; j < 610; j++)
- d[i][j] = f[i][j] = -1;
- scanf("%d%d%d", &n, &k, &p);
- for (int i = 0; i < k; i++)
- scanf("%d", &b[i]);
- for (int i = 0; i < n; i++) {
- scanf("%d%d", &t[i].a, &t[i].c);
- t[i].c--;
- t[i].n = i + 1;
- }
- sort(&t[0], &t[n], cmpT);
- for (int i = 0; i < n; i++) {
- if (t[i].a + b[t[i].c] <= p) {
- d[i][1] = t[i].a + b[t[i].c];
- r = 1;
- }
- }
- for (int tCnt = 2; tCnt <= n; tCnt++) {
- for (int tLast = 0; tLast < n; tLast++) {
- for (int tPred = 0; tPred < tLast; tPred++) {
- if (d[tPred][tCnt - 1] == -1)
- continue;
- int pp = d[tPred][tCnt - 1] + t[tLast].a;
- if (t[tLast].c != t[tPred].c)
- pp += b[t[tLast].c];
- if (pp <= p && (d[tLast][tCnt] == -1 || pp < d[tLast][tCnt])) {
- d[tLast][tCnt] = pp;
- f[tLast][tCnt] = tPred;
- r = tCnt;
- }
- }
- }
- }
- printf("%d\n", r);
- if (r) {
- int tCnt = r, tLast = 0;
- while (d[tLast][tCnt] == -1)
- tLast++;
- while (tCnt) {
- printf("%d ", t[tLast].n);
- tLast = f[tLast][tCnt--];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement