Submission #72983

#TimeUsernameProblemLanguageResultExecution timeMemory
72983garyyeStove (JOI18_stove)C++14
100 / 100
39 ms1532 KiB
// author: gary // created: 2018/08/27 12:55:13 #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <limits> #include <utility> #include <functional> #include <string> #include <bitset> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <algorithm> #include <iostream> #include <sstream> using namespace std; #define SZ(x) ( (int) (x).size() ) #define ALL(c) (c).begin(), (c).end() #define CNT(c, x) ((c).find(x) != (c).end()) typedef pair<int, int> pii; typedef long long ll; template<class T> bool cmax(T& a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> bool cmin(T& a, T b) { if(a > b) { a = b; return true; } return false; } const int N = 1e5 + 10; int t[N]; int a[N]; int n, k; int main() { while(scanf("%d%d", &n, &k) != EOF) { for(int i = 0; i < n; i++) { scanf("%d", t + i); if(i > 0) { a[i - 1] = t[i] - t[i - 1] - 1; } } sort(a, a + n - 1); reverse(a, a + n - 1); int ans = t[n - 1] + 1 - t[0]; for(int i = 0; i < k - 1; i++) { ans -= a[i]; } printf("%d\n", ans); } return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:44:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", t + i);
       ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...