Submission #1110346

# Submission time Handle Problem Language Result Execution time Memory
1110346 2024-11-09T09:47:06 Z the_ZHER Stove (JOI18_stove) C++17
0 / 100
207 ms 262144 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]){
      |            ~^~~~~~~~~~
stove.cpp:15:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:16:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |    freopen("output.txt", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 207 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 207 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 207 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -