답안 #1110347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110347 2024-11-09T09:47:41 Z the_ZHER Stove (JOI18_stove) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int N = 1e5 + 4;
const int inf = 1e18;
struct edge {
    int a,b,c,d;
};
vector<int>v;
vector<pair<int,int> >v1;
vector<int>v2;
signed main(){
 //freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    boost;
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        v.push_back(x);
    }
    for(int i=0;i<n-1;i++){
        v1.push_back({v[i+1]-v[i]-1,i});
    }
    sort(v1.rbegin(),v1.rend());
    for(int i=0;i<k-1;i++){
        v2.push_back(v1[i].second);
    }
    sort(v2.begin(),v2.end());
    int j=0;
    int st=0;
    int ans=0;
    if(v2.size()==1){
        cout<<v[n-1]-v[0]+1;
        return 0;
    }
    for(int i=0;i<v.size();i++){
        if(j<v2.size()&&i==v2[j]){
            j++;
            ans+=v[i]+1-v[st];
            st=i+1;
        }
    }
    ans+=v[n-1]-v[st]+1;
    cout<<ans;
}

Compilation message

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