ÇöÀç °úÁ¦ÁßÀε¥ ÀÚ²Ù·±Å¸ÀÓ ¿¡·¯³ª¿Í¿ä¤Ð¤Ì¤Ð µµ´ëü ¹¹°¡ ¹®Á¦ÀÎÁö ¸ð¸£°Ú½À´Ï´Ù. (äÁ¡¼¹ö¿¡¼ Á¦ÃâÇÏ¸é ·±Å¸ÀÓ¿¡·¯°¡ ³ª¿À°í Á¦ pc¿¡¼´Â ¸ÖÂÄÇÕ´Ï´Ù, ¾Æ¸¶ input°ª¿¡¼ ·±Å¸ÀÓ¿¡·¯°¡ ³ª´Â°Í°°½À´Ï´Ù.)
#include
#include
#include
using namespace std;
int S[1000000];
int ST[100000000];
int main() {
ifstream inStream("input.txt");
int numCases;
int N;
int T;
int num;
int K;
int Snum;
int SUM;
inStream >> numCases;
for (int i = 0; i < numCases; i++) {//TestCase ¸¸Å ¹Ýº¹<br />
int total_num = 0;
int ST_num = 0;
int *ST_ptr = ST;
int count = 0;
inStream >> N;
num = N;
inStream >> T;
K = T;
for (int j = 0; j < N; j++) { // SÀÇ ¿ø¼ÒµéÀ» input<br />
inStream >> Snum;
S[j] = Snum;
}
for (int a = 0; a < num; a++) {<br />
for (int b = a + 1; b < num; b++) {<br />
SUM = K - (S[a] + S[b]);
if (SUM < 0) SUM = SUM*(-1);<br />
ST_ptr[ST_num] = SUM;
ST_num++;
}
}
if (num > 1) {
total_num = (num*(num - 1)) / 2;
}
sort(ST, ST+total_num);
for (int c = 0; c < total_num;) {<br />
if (ST[c] > ST[0]) break;
count++;
c++;
}
cout << count << endl;<br />
}
return 0;
}
Âü°í·Î input °ªÀº 2<=N<=1000000, -10^8 <=K <= 10^8 , -10^8 <=Snum <= 10^8 ÀÔ´Ï´Ù.¤Ð¤Ì¤Ð ºÎŹµå·Á¿ä¤Ð¤Ì<br />
+±Û¿¡¼´Â ¾Èº¸À̴µ¥ include´Â iostream fstream algorithm ¼¼°¡Áö Çß½À´Ï´Ù. | |
|
»ó´ë°æ·ÎÀÎÁö Àý´ë°æ·ÎÀÎÁö.