제출 #1336732

#제출 시각아이디문제언어결과실행 시간메모리
1336732nguyengiabach1201Coins (BOI06_coins)C++20
100 / 100
56 ms4792 KiB
// https://oj.uz/problem/view/BOI06_coins

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define el '\n'
#define FNAME "coins"
#define ll long long
#define int long long
#define ld long double

const int MOD = 1e9 + 7;
const ll INF = 1e18 + 7;
const double EPS = 1e-9;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    if (fopen(FNAME ".in", "r"))
    {
        freopen(FNAME ".in", "r", stdin);
        freopen(FNAME ".out", "w", stdout);
    }

    return;
}

const int N = 5e5 + 5;
int n, k, c[N];
bool d[N];

void solve()
{
    cin >> n >> k;

    for (int i = 1; i <= n; ++i)
        cin >> c[i] >> d[i];

    int currentChangeSum = 0;
    int newDenominationsCount = 0;

    for (int i = 1; i <= n; ++i)
    {
        if (!d[i])
        {
            int nextDenom = (i == n) ? k : c[i + 1];

            if (currentChangeSum + c[i] < nextDenom)
            {
                currentChangeSum += c[i];
                newDenominationsCount++;
            }
        }
    }

    cout << newDenominationsCount << el;

    if (newDenominationsCount == 0)
        cout << k - 1 << el;
    else
        cout << k - currentChangeSum << el;

    return;
}

signed main()
{
    setup();

    int t = 1;
    bool multiTest = false;

    if (multiTest)
        cin >> t;

    while (t--)
        solve();

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

coins.cpp: In function 'void setup()':
coins.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(FNAME ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
coins.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(FNAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...