Submission #330743

#TimeUsernameProblemLanguageResultExecution timeMemory
330743M_WStove (JOI18_stove)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; #define ii pair<int, int> struct cmp{ bool operator()(const ii &a, const ii &b) const{ return abs(a.first - a.second) < abs(b.first - b.second); } }; int main(){ priority_queue<ii, vector<ii>, cmp> pq; int N, K, cur, old, maxt = INT_MIN; scanf("%d %d %d", &N, &K, &old); for(int i = 1; i < N; i++){ scanf("%d", &cur); pq.push(make_pair(old + 1, cur)); old = cur; maxt = max(maxt, cur + 1); } K--; vector<int> v; while(!pq.empty() && K > 0){ int s = pq.top().first; int e = pq.top().second; pq.pop(); v.push_back(s); v.push_back(e); K--; } v.push_back(1); v.push_back(maxt); sort(v.begin(), v.end()); int sz = v.size(); int tuse = 0; for(int i = 0; i < sz; i += 2){ tuse += v[i + 1] - v[i]; } printf("%d", tuse); }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  scanf("%d %d %d", &N, &K, &old);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d", &cur);
      |   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...