|
|
back to boardWhy WA5? Help!!! Posted by tester 5 Aug 2009 15:01 This is my program: #include <stdio.h> int main () { int n; int mas[100][3] = {}; bool maska[100] = {}; int solution = 0; int sum = 0; int min = 601, k = 0; scanf ("%d", &n); for (int i = 0; i < n; i++) { scanf ("%d%d%d", &mas[i][0], &mas[i][1], &mas[i][2]); if (mas[i][0] < min) { min = mas[i][0]; k = i; } } sum = mas[k][0]; maska[k] = 1; bool ok = false; int exit = 0; int save_i = 0; while (ok == false) { min = 9999999; sum += mas[k][1]; maska[k] = 1; ok = true; if (sum > mas[k][2]) solution += sum - mas[k][2]; bool key = false; exit = k; if (k == n - 1) k = -1; for (int i = k + 1; i < n; i++) { if (exit == i) break; if (maska[i] == 1) ok = true; if ((maska[i] == 0) && (mas[i][0] > sum) && (mas[i][0] < min)) { min = mas[i][0]; save_i = i; key = true; } if ((maska[i] == 0) && (mas[i][0] <= sum)) { k = i; ok = false; break; } if (i == n - 1) i = -1; } if ((ok == true) && (key == true)) { ok = false; k = save_i; sum = mas[k][0]; } } printf ("%d", solution); return 0; } |
|
|