답안 #519846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519846 2022-01-27T12:19:57 Z Lam_lai_cuoc_doi 금 캐기 (IZhO14_divide) C++17
48 / 100
1000 ms 3560 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <class T>
void read(T &x)
{
    x = 0;
    register int c;
    while ((c = getchar()) && (c > '9' || c < '0'))
        ;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

constexpr bool typetest = 0;
constexpr int N = 1e5 + 5;
int n;
struct miningcamp
{
    int x;
    ll g, e;
    miningcamp(int x = 0, ll g = 0, ll e = 0) : x(x), g(g), e(e) {}

    bool operator<(const miningcamp &a) const
    {
        return x < a.x;
    }
} a[N];

void Read()
{
    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> a[i].x >> a[i].g >> a[i].e;
}

void Solve()
{
    sort(a + 1, a + n + 1);

    for (int i = 1; i <= n; ++i)
    {
        a[i].e += a[i - 1].e;
        a[i].g += a[i - 1].g;
    }

    ll ans(0);

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= i; ++j)
            if (a[i].e - a[j - 1].e >= a[i].x - a[j].x)
                ans = max(ans, a[i].g - a[j - 1].g);

    cout << ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("tests.inp", "r"))
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        // cout << "Case " << _ << ": ";
        Read();
        Solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

/*
 */

Compilation message

divide.cpp: In function 'void read(T&)':
divide.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     register int c;
      |                  ^
divide.cpp: In function 'int32_t main()':
divide.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 2 ms 2676 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 4 ms 2696 KB Output is correct
19 Correct 2 ms 2676 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 4 ms 2672 KB Output is correct
23 Correct 19 ms 2764 KB Output is correct
24 Correct 16 ms 2776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 2 ms 2676 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 4 ms 2696 KB Output is correct
19 Correct 2 ms 2676 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 4 ms 2672 KB Output is correct
23 Correct 19 ms 2764 KB Output is correct
24 Correct 16 ms 2776 KB Output is correct
25 Correct 18 ms 2700 KB Output is correct
26 Correct 62 ms 2764 KB Output is correct
27 Correct 79 ms 2828 KB Output is correct
28 Execution timed out 1062 ms 3560 KB Time limit exceeded
29 Halted 0 ms 0 KB -