Submission #385888

#TimeUsernameProblemLanguageResultExecution timeMemory
385888ismoilovStove (JOI18_stove)C++14
100 / 100
27 ms2028 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fv(c) for(int (a) = (1); (a) <= (c); (a)++)
#define fz(c) for(int (a) = (0); (a) < (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
#define pb push_back
#define in insert
#define ss second
#define ff first
void S()
{
	int n, k, ans = 0;
	cin >> n >> k;
	vector <int> a(n), b(n, 0);
	fp(i,0,n)
		cin >> a[i];
	fp(i,1,n)
		b[i] = a[i] - a[i-1], ans += b[i];
	ans ++;
	//cout << ans << "\n";
	sort(rall(b));
	fp(i,0,k-1)
		ans -= b[i] - 1;
	cout << ans << endl;
}
int main()
{
	IOS;
	S();
	/*int t;
	cin >> t;
	while(t--)
		 S();*/
}

Compilation message (stderr)

stove.cpp: In function 'void S()':
stove.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
stove.cpp:24:2: note: in expansion of macro 'fp'
   24 |  fp(i,0,n)
      |  ^~
stove.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
stove.cpp:26:2: note: in expansion of macro 'fp'
   26 |  fp(i,1,n)
      |  ^~
stove.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
stove.cpp:31:2: note: in expansion of macro 'fp'
   31 |  fp(i,0,k-1)
      |  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...