답안 #200907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200907 2020-02-08T13:34:35 Z SamAnd Hokej (COCI17_hokej) C++17
72 / 120
186 ms 11280 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
struct ban
{
    int i;
    int k, d;
};
bool operator<(const ban& a, const ban& b)
{
    return a.k < b.k;
}

int m, n;
ban a[N];

int u[6];
int p[6];
int s[6];

vector<pair<int, pair<int, int> > > v;

int main()
{
    scanf("%d%d", &m, &n);
    for (int i = 1; i <= n; ++i)
    {
        a[i].i = i;
        scanf("%d%d", &a[i].k, &a[i].d);
    }
    sort(a + 1, a + n + 1);
    long long ans = 0;
    int j = 0;
    for (int i = n; i >= 1; --i)
    {
        a[i].d = min(a[i].d, m);
        while (1)
        {
            if (j == 6)
                break;
            if (u[j] + a[i].d <= m)
            {
                if (p[j] == 0)
                    s[j] = a[i].i;
                else
                {
                    if (u[j] != m)
                        v.push_back({u[j], {p[j], a[i].i}});
                }
                p[j] = a[i].i;
                ans += (a[i].d * 1LL * a[i].k);
                u[j] += a[i].d;
                a[i].d = 0;
                break;
            }
            else
            {
                if (p[j] == 0)
                    s[j] = a[i].i;
                else
                {
                    if (u[j] != m)
                        v.push_back({u[j], {p[j], a[i].i}});
                }
                p[j] = a[i].i;
                ans += ((m - u[j]) * 1LL * a[i].k);
                a[i].d -= (m - u[j]);
                u[j] = m;
                ++j;
            }
        }
    }
    printf("%lld\n", ans);
    for (int i = 0; i < 6; ++i)
        printf("%d ", s[i]);
    printf("\n");
    sort(v.begin(), v.end());
    printf("%d\n", v.size());
    for (int i = 0; i < v.size(); ++i)
        printf("%d %d %d\n", v[i].first, v[i].second.first, v[i].second.second);
    return 0;
}

Compilation message

hokej.cpp: In function 'int main()':
hokej.cpp:78:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<int, std::pair<int, int> > >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", v.size());
                    ~~~~~~~~^
hokej.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
hokej.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &m, &n);
     ~~~~~^~~~~~~~~~~~~~~~
hokej.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i].k, &a[i].d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 13 ms 888 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 8 ms 632 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Incorrect 8 ms 504 KB Output isn't correct
8 Incorrect 35 ms 2552 KB Output isn't correct
9 Incorrect 178 ms 11280 KB Output isn't correct
10 Incorrect 186 ms 11256 KB Output isn't correct