绝了
  • 板块CF34B Sale
  • 楼主_Cloud_
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/9/25 16:49
  • 上次更新2023/11/4 05:40:50
查看原帖
绝了
247992
_Cloud_楼主2021/9/25 16:49

两份一模一样的代码,第一遍交时在#3WA(输出-84)了,多交几遍就AC了?!

#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 1e2 + 5;

void read(int &x) {
    int f = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
    for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    x *= f;
}

//bool cmp(int x, int y) { return x > y; }

int a[N];


int main() {
    int n, m;
    read(n), read(m);
    int now = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        read(a[i]);
        //if (now <= m && a[i] < 0) ans -= a[i], now++;
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= m; i++) {
        if (a[i] < 0) ans -= a[i];
        else break;
    }
    printf("%d\n", ans);
    return 0;
}

兼WA又AC的代码……

2021/9/25 16:49
加载中...