답안 #647967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647967 2022-10-04T17:18:07 Z rohith_231 Stove (JOI18_stove) C++17
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n,k; cin>>n>>k;
  vector<int>arr(n); for(size_t i=0;i<n;i++) cin>>arr[i];
  vector<int>diff(n-1);
  for(size_t i=0;i<n-1;i++) {
    diff[0] = arr[i+1]-arr[i]-1;
  }
   sort(diff.begin(),diff.end(),greater<int>());
  int res = arr[n-1]+1-arr[0];
  for(size_t i=0;i<k-1;i++) res-=diff[i];
  cout<<res<<endl;
  
  return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:9:38: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    9 |   vector<int>arr(n); for(size_t i=0;i<n;i++) cin>>arr[i];
      |                                     ~^~
stove.cpp:11:19: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   11 |   for(size_t i=0;i<n-1;i++) {
      |                  ~^~~~
stove.cpp:16:19: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |   for(size_t i=0;i<k-1;i++) res-=diff[i];
      |                  ~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -