// Grzegorz Chuchro #include <stdio.h> #include <stdlib.h> unsigned int damage_and_regeneration_positive[100000][3]; int damage_and_regeneration_positive_size; unsigned int damage_and_regeneration_negative[100000][3]; // and 0 int damage_and_regeneration_negative_size; int compare(const void *a, const void *b){ return (*(unsigned int*)a-*(unsigned int*)b); } int compare2(const void *a, const void *b){ //return (((((unsigned int*)a)[1])-(((unsigned int*)a)[0]))-((((unsigned int*)b)[1])-(((unsigned int*)b)[0]))); return ((unsigned int*)b)[1]-((unsigned int*)a)[1]; //return (((unsigned int*)b)[1]-((unsigned int*)b)[0])-(((unsigned int*)a)[1]-((unsigned int*)a)[0]); } int main(){ int n; int i; unsigned long long int health; unsigned int damage, regeneration; scanf("%d%llu", &n, &health); damage_and_regeneration_positive_size = 0; damage_and_regeneration_negative_size = 0; i = 1; while(i<=n){ scanf("%u%u", &damage, ®eneration); if(damage<regeneration){ damage_and_regeneration_positive[damage_and_regeneration_positive_size][0] = damage; damage_and_regeneration_positive[damage_and_regeneration_positive_size][1] = regeneration; damage_and_regeneration_positive[damage_and_regeneration_positive_size++][2] = i; } else{ damage_and_regeneration_negative[damage_and_regeneration_negative_size][0] = damage; damage_and_regeneration_negative[damage_and_regeneration_negative_size][1] = regeneration; damage_and_regeneration_negative[damage_and_regeneration_negative_size++][2] = i; } ++i; } qsort(damage_and_regeneration_positive, damage_and_regeneration_positive_size, sizeof(unsigned int)*3, compare); // treat as simple arr i = 0; while(i<damage_and_regeneration_positive_size){ if(damage_and_regeneration_positive[i][0]<health){ health -= damage_and_regeneration_positive[i][0]; health += damage_and_regeneration_positive[i][1]; } else{ // error puts("NIE"); return 0; } ++i; } qsort(damage_and_regeneration_negative, damage_and_regeneration_negative_size, sizeof(unsigned int)*3, compare2); // treat as simple arr i = 0; while(i<damage_and_regeneration_negative_size){ if(damage_and_regeneration_negative[i][0]<health){ health -= damage_and_regeneration_negative[i][0]; health += damage_and_regeneration_negative[i][1]; } else{ // error puts("NIE"); return 0; } ++i; } puts("TAK"); i = 0; while(i<damage_and_regeneration_positive_size){ printf("%u ", damage_and_regeneration_positive[i][2]); ++i; } i = 0; while(i<damage_and_regeneration_negative_size){ printf("%u ", damage_and_regeneration_negative[i][2]); ++i; } return 0; }
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 | // Grzegorz Chuchro #include <stdio.h> #include <stdlib.h> unsigned int damage_and_regeneration_positive[100000][3]; int damage_and_regeneration_positive_size; unsigned int damage_and_regeneration_negative[100000][3]; // and 0 int damage_and_regeneration_negative_size; int compare(const void *a, const void *b){ return (*(unsigned int*)a-*(unsigned int*)b); } int compare2(const void *a, const void *b){ //return (((((unsigned int*)a)[1])-(((unsigned int*)a)[0]))-((((unsigned int*)b)[1])-(((unsigned int*)b)[0]))); return ((unsigned int*)b)[1]-((unsigned int*)a)[1]; //return (((unsigned int*)b)[1]-((unsigned int*)b)[0])-(((unsigned int*)a)[1]-((unsigned int*)a)[0]); } int main(){ int n; int i; unsigned long long int health; unsigned int damage, regeneration; scanf("%d%llu", &n, &health); damage_and_regeneration_positive_size = 0; damage_and_regeneration_negative_size = 0; i = 1; while(i<=n){ scanf("%u%u", &damage, ®eneration); if(damage<regeneration){ damage_and_regeneration_positive[damage_and_regeneration_positive_size][0] = damage; damage_and_regeneration_positive[damage_and_regeneration_positive_size][1] = regeneration; damage_and_regeneration_positive[damage_and_regeneration_positive_size++][2] = i; } else{ damage_and_regeneration_negative[damage_and_regeneration_negative_size][0] = damage; damage_and_regeneration_negative[damage_and_regeneration_negative_size][1] = regeneration; damage_and_regeneration_negative[damage_and_regeneration_negative_size++][2] = i; } ++i; } qsort(damage_and_regeneration_positive, damage_and_regeneration_positive_size, sizeof(unsigned int)*3, compare); // treat as simple arr i = 0; while(i<damage_and_regeneration_positive_size){ if(damage_and_regeneration_positive[i][0]<health){ health -= damage_and_regeneration_positive[i][0]; health += damage_and_regeneration_positive[i][1]; } else{ // error puts("NIE"); return 0; } ++i; } qsort(damage_and_regeneration_negative, damage_and_regeneration_negative_size, sizeof(unsigned int)*3, compare2); // treat as simple arr i = 0; while(i<damage_and_regeneration_negative_size){ if(damage_and_regeneration_negative[i][0]<health){ health -= damage_and_regeneration_negative[i][0]; health += damage_and_regeneration_negative[i][1]; } else{ // error puts("NIE"); return 0; } ++i; } puts("TAK"); i = 0; while(i<damage_and_regeneration_positive_size){ printf("%u ", damage_and_regeneration_positive[i][2]); ++i; } i = 0; while(i<damage_and_regeneration_negative_size){ printf("%u ", damage_and_regeneration_negative[i][2]); ++i; } return 0; } |