编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#100420 #1022. jwp的排队难题 Compile Error 0 0 ms 0 K C++ 11 / 896 B Qling 2023-07-24 15:52:38
显示原始代码
#include <bits/stdc++.h>
using namespace std;

struct c {
    int a, b;
    bool operator<(const c &o) const { return b < o.b; }
};
c a[100005];

int main() {
    int n, s = 0, sum = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a[i].a, &a[i].b);
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        s += a[i].b;
        sum += s * a[i].a;
    }
    printf("%d", sum);
    return 0;
#include <bits/stdc++.h>
    using namespace std;

    struct c {
        int a, b;
        bool operator<(const c &o) const { return b > o.b; }
    };
    c a[100005];

    int main() {
        long long n, s = 0, sum = 0;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%d%d", &a[i].a, &a[i].b);
        }
        sort(a + 1, a + n + 1);
        // for (int i = 1;i <= n;i++) printf("%d ",a[i]);
        for (int i = 1; i <= n; i++) {
            s += a[i].b;
            sum += s * a[i].a;
        }
        printf("%d", sum);
        return 0;
    }

编译信息

/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:44:1: error: a function-definition is not allowed here before '{' token
   44 | {
      | ^
/sandbox/1/a.cpp:60:1: error: expected '}' at end of input
   60 | }
      | ^
/sandbox/1/a.cpp:15:1: note: to match this '{'
   15 | {
      | ^
/sandbox/1/a.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
/sandbox/1/a.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d%d",&a[i].a,&a[i].b);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~