The input is before each '(',
We need to find the number of ')' before each ')',
My method is to restore the original graph and then look ')'.
Do not reuse tags that have been paired ..
# Include <stdio. h> # include <string. h> int y [505], t [505]; char s [505]; int main () {int A, B, I, J, U; scanf ("% d", & A); While (A --) {memset (Y, 0, sizeof (y); memset (T, 0, sizeof (t); memset (S, 0, sizeof (s); scanf ("% d", & B); for (I = 0; I <B; I ++) {scanf ("% d", & Y [I]) ;}int sum = 1; int ans; for (I = 0, j = 0; I <505; I ++) {If (sum <= Y [J]) {s [I] = '('; sum ++ ;} else {s [I] = ')'; j ++;} If (j> = B) break;} u = strlen (s); for (I = 0; I <u; I ++) {If (s [I] = '(') continue; else {ans = 1; t [I] = 1; for (j = I-1; j> = 0; j --) {If (s [J] = ') ans ++; if (T [J] = 0) {If (s [J] = '(') {T [J] = 1; break ;}}} printf ("% d", ANS) ;}} printf ("\ n") ;}return 0 ;}