Submission #708079

#TimeUsernameProblemLanguageResultExecution timeMemory
708079yellowtoadStove (JOI18_stove)C++17
100 / 100
63 ms4752 KiB
#include <iostream> #include <vector> #include <algorithm> #define int long long using namespace std; int n, k, a[100010], ans; pair<int,int> d[100010]; vector<int> b; signed main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) d[i] = {a[i+1]-a[i],i}; sort(d+1,d+n,greater<pair<int,int>>()); b.push_back(0); for (int i = 1; i < k; i++) b.push_back(d[i].second); b.push_back(n); for (int i = 1; i < b.size(); i++) ans += a[b[i]]+1-a[b[i-1]+1]; cout << ans << endl; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:19:20: 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]
   19 |  for (int i = 1; i < b.size(); i++) ans += a[b[i]]+1-a[b[i-1]+1];
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...