#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
int my_compare(const void* pierwszy,const void* drugi) {
int* p = *(int**)pierwszy;
int* d = *(int**)drugi;
//printf("%d %d\n",p[0],d[0]);
if (p[2] < 0 and d[2] >= 0) { return 1;}
if (p[2] < 0 and d[2] < 0 and (p[1]+p[2]) < (d[1]+d[2])) { return 1;}
if (p[2] > 0 and d[2] > 0 and p[1] > d[1]) { return 1;}
if (p[1] == d[1]) { return 0; }
return -1;
}
int main() {
int zycie = 0;
int potwory = 0;
scanf("%d",&potwory);
scanf("%d",&zycie);
int** lista = (int**) malloc (sizeof(int*)*potwory);
for (int i = 0; i<potwory; i++) {
lista[i] = (int*) malloc (sizeof(int)*3);
lista[i][0] = i;
scanf("%d",&(lista[i][1]));
scanf("%d",&(lista[i][2]));
lista[i][2] = lista[i][2] - lista[i][1];
}
qsort((void*)lista,potwory,sizeof(int*),my_compare);
for (int i = 0; i<potwory;i++) {
//printf("%d %d %d\n",lista[i][0],lista[i][1],lista[i][2]);
}
int i = 0;
for (i = 0; i<potwory;i++) {
if (lista[i][2] < 0) { break;}
if (lista[i][1] > zycie) {
printf("NIE\n");
return(0);
}
zycie += lista[i][2];
}
int zycie_down = 0;
if (i < potwory) {
zycie_down = -lista[potwory-1][1];
for (; i < potwory-1; i++) {
zycie_down += lista[i][2];
}
}
if (zycie + zycie_down <= 0) { printf("NIE\n"); return(0); }
//printf("%d %d\n",zycie,zycie_down);
printf("TAK\n");
for (int i = 0; i < potwory; i++) { printf("%d",lista[i][0]+1); i<(potwory-1) ? printf(" ") : printf("\n");}
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 | #include <stdio.h> #include <stdlib.h> #include <stdio.h> int my_compare(const void* pierwszy,const void* drugi) { int* p = *(int**)pierwszy; int* d = *(int**)drugi; //printf("%d %d\n",p[0],d[0]); if (p[2] < 0 and d[2] >= 0) { return 1;} if (p[2] < 0 and d[2] < 0 and (p[1]+p[2]) < (d[1]+d[2])) { return 1;} if (p[2] > 0 and d[2] > 0 and p[1] > d[1]) { return 1;} if (p[1] == d[1]) { return 0; } return -1; } int main() { int zycie = 0; int potwory = 0; scanf("%d",&potwory); scanf("%d",&zycie); int** lista = (int**) malloc (sizeof(int*)*potwory); for (int i = 0; i<potwory; i++) { lista[i] = (int*) malloc (sizeof(int)*3); lista[i][0] = i; scanf("%d",&(lista[i][1])); scanf("%d",&(lista[i][2])); lista[i][2] = lista[i][2] - lista[i][1]; } qsort((void*)lista,potwory,sizeof(int*),my_compare); for (int i = 0; i<potwory;i++) { //printf("%d %d %d\n",lista[i][0],lista[i][1],lista[i][2]); } int i = 0; for (i = 0; i<potwory;i++) { if (lista[i][2] < 0) { break;} if (lista[i][1] > zycie) { printf("NIE\n"); return(0); } zycie += lista[i][2]; } int zycie_down = 0; if (i < potwory) { zycie_down = -lista[potwory-1][1]; for (; i < potwory-1; i++) { zycie_down += lista[i][2]; } } if (zycie + zycie_down <= 0) { printf("NIE\n"); return(0); } //printf("%d %d\n",zycie,zycie_down); printf("TAK\n"); for (int i = 0; i < potwory; i++) { printf("%d",lista[i][0]+1); i<(potwory-1) ? printf(" ") : printf("\n");} return(0); } |
English