제출 #928797

#제출 시각아이디문제언어결과실행 시간메모리
928797AtabayRajabliStove (JOI18_stove)C++17
100 / 100
16 ms3316 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
 
// author : a1abay
// (a / b) % c = (a * b ^ (mod - 2)) % c;
 
#define pb          push_back
#define pii         pair<int, int>
#define all(v)      v.begin(), v.end()
#define se          second
#define fi          first
#define int         ll
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   (a*b / (__gcd(a, b)))
#define mpr         make_pair
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         ld;
const int inf =             1e9 + 7;
const int inff =            1e18 + 7;
const int sz =              2e5 + 5;
using namespace             std;
 
void open(string s, string f)
{
    freopen((s + ".txt").c_str(), "r", stdin);
    freopen((f + ".txt").c_str(), "w", stdout);
}

int mod = 998244353;
int D = 69;

int n, k;
int a[sz];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    // open("in", "out");

    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    } 

    vector<int> v;
    for(int i = 2; i <= n; i++)
    {
        v.pb(a[i] - a[i - 1] - 1);
    }

    sort(all(v), greater<int>());

    int ans = a[n] + 1 - a[1];
    for(int i = 0; i < k -1; i++)
    {
        ans -= v[i];
    }

    cout << ans << endl;
}  

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

stove.cpp: In function 'void open(std::string, std::string)':
stove.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen((s + ".txt").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen((f + ".txt").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...