问下这份代码为啥会wa
查看原帖
问下这份代码为啥会wa
139012
wrpwrp楼主2020/5/20 10:45
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define R register
#define LL long long
const int inf = 0x3f3f3f3f;
const int N = 5e4 + 10;

inline int read() {
	char a = getchar(); int x = 0,f = 1;
	for(;a > '9' || a < '0';a = getchar()) if(a == '-') f = -1;
	for(;a >= '0' && a <= '9'; a = getchar()) x = x * 10 + a - '0';
	return x * f;
}

int n;
struct Node { int w, l; } t[N];

inline bool cmp(Node x, Node y) { return x.l == y.l ? x.w < y.w : x.l < y.l;}

Node stk[N]; int top;
LL f[N];
int main() {
	freopen("a.in","r",stdin);
	//freopen(".out","w",stdout);
	n = read();
	for(R int i = 1; i <= n; i ++) 
		t[i].w = read(), t[i].l = read();
	sort(t + 1, t + 1 + n, cmp);
	for(R int i = 1; i <= n; i ++) {
		if(top && stk[top].w <= t[i].w) top --;
		stk[++ top] = t[i];
	}
	memset(f, inf, sizeof(f));
	
	f[0] = 0;
	for(R int i = 1; i <= top; i ++)
		for(R int j = 0; j < i; j ++)
			f[i] = min(f[i], f[j] + 1LL * stk[i].l * stk[j + 1].w );
	printf("%lld\n", f[top]);
	return 0;	
}

它在下面这个数据挂了

10
811 1153
781 1932
1367 399
1213 1212
1910 54
194 616
1382 1367
1186 632
975 1651
1215 621
2773164
2020/5/20 10:45
加载中...