Time Lapse :3min 2sec 1208.cpp1234567891011121314151617181920212223242526272829303132#include <iostream>#include <vector>#include <algorithm>using namespace std;#define gc() getchar_unlocked()inline void fastreadINT_byReference(int &ret){ int N = gc(), flag = 1; for(;N<'0'||N>'9';N=gc()) if(N=='-'){ flag=-1; N=gc(); break; } ret = 0; do{ ret = (ret<<3) + (ret<<1) + (N & 0b1111); N=gc(); }while('0'<=N&&N<='9'); ret *= flag;}int main() { int tc = 1, T = 10, dump; vector<int> vec = vector<int>(100); while(T--) { fastreadINT_byReference(dump); for(int i = 0; i < 100; ++i) fastreadINT_byReference(vec[i]); while(dump--) { --(*max_element(vec.begin(), vec.end())); ++(*min_element(vec.begin(), vec.end())); } printf("#%d %d\n",tc++, *max_element(vec.begin(), vec.end()) - *min_element(vec.begin(), vec.end())); }} 1208.java12345678910111213141516171819202122232425262728293031323334import java.util.*;public class Solution { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int tc = 1, T = 10, dump; while(T-- != 0) { dump = scanner.nextInt(); List<Integer> map = new ArrayList<>(); for(int i = 0; i < 100; ++i) { map.add(scanner.nextInt()); } while(dump-- != 0) { int max = Collections.max(map); int min = Collections.min(map); boolean minFlag = false, maxFlag = false; int index = 0; for(int val : map) { if(maxFlag && minFlag) break; if(!maxFlag && val == max) { map.set(index, val - 1); maxFlag = true; } if(!minFlag && val == min) { map.set(index, val + 1); minFlag = true; } ++index; } } System.out.println("#" + tc++ + " " + (Collections.max(map) - Collections.min(map))); } }}