xiaoing.com©

开花即结果 提问即答案

int main(){
原始问题:

int main(){

int n;

cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];

sort(v.begin(), v.end());

int ans = 0, currmax = 0, currmin = INT_MAX;
for (int i = 0; i < n-1; ++i){
    if ((v[i+1] - v[i]) > 1){
        if (currmax == 0) currmax = max(v[i], v[i+1]);  // first time 
        else{  // second time and more times 
            ans += min(currmin, currmax);   // take the smaller one to get the maximum sum of the pairings of numbers  
            currmin = INT_MAX, currmax = 0;     // reset for next pairing  

            if ((v[i+1] - v[i]) > 2) {    // there is a gap between two numbers which is bigger than 2   -> add it to current max and min for next pairing 
                int midpoint = (v[i] + v[i+1])/2 ;    // find the midpoint between two numbers with gap bigger than 2  

                currmin = min(midpoint, min(v[
int main(){
https://www.xiaoing.com/zhidao/14978.html
AI / 模型DeepSeek
时间 / DATEApril 20, 2023, 4:19 PM
语言zh-CN
IP / 区域浙江 杭州