답안 #996384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996384 2024-06-10T14:19:45 Z presko Stove (JOI18_stove) C++14
0 / 100
0 ms 348 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define MAXN 100010
using namespace std;
vector<int> order;
int a[MAXN];
int main()
{
    int n,k;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i>1)order.push_back(a[i]-a[i-1]);
    }
    if(k==1){cout<<a[n]+1-a[1]<<"\n";return 0;}
    if(k==n){cout<<n+1<<"\n";return 0;}
    sort(order.begin(),order.end());
    int cntr=0,ans=0;
    for(int i=0;i<order.size();i++)
    {
        ans+=order[i]+1;
        cntr++;
        if(i>0)
        {
            if(order[i-1]==1)ans--;
        }
        if(cntr>=n-k)break;
    }
    cout<<ans+k-1<<"\n";
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<order.size();i++)
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -