제출 #1229465

#제출 시각아이디문제언어결과실행 시간메모리
1229465duyhoanhoStove (JOI18_stove)C++17
100 / 100
17 ms2384 KiB
//ngocuti
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second

using namespace std;
const int N = 1e5 + 10;
int n, k, a[N];
priority_queue<int> q;
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  if(fopen("task.inp","r")){
      freopen("task.inp","r",stdin);
      freopen("task.out","w",stdout);
  }
  #define task ""
  if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
  }

  cin >> n >> k;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int ans = n;
  k--;
  int sum = 0;
  for(int i = 2; i <= n; i++){
    q.push(a[i] - a[i - 1] - 1);
  }
  while(q.size() && k--) q.pop();
  while(q.size()){
    int u = q.top(); q.pop();
    sum += u;
  }
  cout<<sum + ans;
}

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

stove.cpp: In function 'int32_t main()':
stove.cpp:17:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |       freopen("task.inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:18:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |       freopen("task.out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:22:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:23:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...