Submission #133123

#TimeUsernameProblemLanguageResultExecution timeMemory
133123ekremCake 3 (JOI19_cake3)C++98
0 / 100
3 ms764 KiB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000000000000009
#define N 2005
using namespace std;

typedef long long ll;
typedef pair < ll , ll > ii;

ll n, m, ans, a[N], b[N], dp[N][N];
ii x[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld %lld",&n ,&m);
	dp[0][1] = -inf;//bura bak
	for(ll i = 1; i <= n; i++){
		scanf("%lld %lld",&x[i].nd ,&x[i].st);
	}
	sort(x + 1, x + n + 1);
	for(int i = 1; i <= n; i++){
		a[i] = x[i].nd;
		b[i] = x[i].st;
		dp[i][1] = max(dp[i - 1][1], a[i] + 2*b[i]);
	}
	for(ll j = 2; j <= m; j++){
		dp[0][j] = -inf;
		for(ll i = 1; i <= n; i++){
			dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1] + a[i]);
		}
	}
	for(ll i = 1; i <= n; i++){
		ans = max(ans, dp[i - 1][m - 1] + a[i] - 2*b[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n ,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
cake3.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&x[i].nd ,&x[i].st);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...