Created
November 18, 2015 15:58
-
-
Save jiunbae/04c3523dad4c776f8909 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <algorithm> | |
| using namespace std; | |
| int main(int argc, char * argv[]) | |
| { | |
| int test; cin >> test; | |
| while(test--) | |
| { | |
| int n, m; cin >> n >> m; | |
| int chk = n * m; | |
| int max = 0; | |
| vector<int> hp(501, 0), count(501, 0); | |
| while(chk--) | |
| { | |
| int temp; cin >> temp; | |
| hp.at(temp)++; | |
| if(max < temp) | |
| max = temp; | |
| } | |
| chk = 0; | |
| for(int idx = 1; idx <= max; idx++) | |
| { | |
| count.at(idx) = count.at(idx-1) + hp.at(idx); | |
| if(count[idx] > idx && hp[idx] && (count[chk] - chk < count[idx] - idx)) | |
| chk = idx; | |
| } | |
| int ret = chk; | |
| for(int idx = chk + 1; idx <= max; idx ++) | |
| if(hp[idx]) | |
| ret+= hp[idx]; | |
| cout << ret << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment