acgo题库
  • 首页
  • 题库
  • 学习
  • 天梯
  • 备赛

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
  • 竞赛
  • 讨论
  • 团队
登录
注册
题目详情提交记录(0)
  • 题解

    #include <iostream> #include <vector> #include <queue> using namespace std; typedef long long LL; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<LL> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i] - i; } priority_queue<LL> max_heap; for (int i = 0; i < n; i++) { max_heap.push(b[i]); if (max_heap.top() > b[i]) { max_heap.pop(); max_heap.push(b[i]); } b[i] = max_heap.top(); } for (int i = n - 2; i >= 0; i--) { if (b[i] > b[i + 1]) { b[i] = b[i + 1]; } } LL total = 0; for (int i = 0; i < n; i++) { total += abs(a[i] - (b[i] + i)); } cout << total << "\n"; for (int i = 0; i < n; i++) { if (i) cout << " "; cout << b[i] + i; } cout << endl; return 0; }

    userId_undefined

    ༺ཌༀ༒☯∞复仇者∞☯༒ༀད༻™

    出道萌新时空双修者8月全勤卷王题解仙人
    3阅读
    0回复
    1点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页