qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-高级专业版🔥

int main(){

时间2023-04-20 16:19:47 提问来自 浙江省杭州市 的网友 分类创作 浏览293
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[

点击这里,进行内容创作

创作工场 免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!

上一篇 东莱在哪里 下一篇 财务管理职业满足兴趣因素