记录编号 |
358237 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOI 2008]志愿者招募 |
最终得分 |
100 |
用户昵称 |
sxysxy |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.514 s |
提交时间 |
2016-12-15 08:51:07 |
内存使用 |
38.73 MiB |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <string>
#include <algorithm>
#include <list>
#include <queue>
#include <vector>
namespace IO
{
char buf[1<<18], *fs, *ft;
inline char readc()
{
return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin),fs==ft))?0:*fs++;
}
inline int fast_read()
{
int r;
char c;
bool s = false;
while(c = readc())
{
if(c >= '0' && c <= '9')
{
r = c^0x30;
break;
}else if(c == '-')s = true;
}
while(isdigit(c = readc()))
r = (r<<3)+(r<<1)+(c^0x30);
return s?-r:r;
}
}using IO::fast_read;
using namespace std;
int n, m;
int a[10001][1001], next[1001];
void pivot(int x, int y)
{
a[x][y] = -1;
for(int i = 0; i <= m; i++)
{
int t;
if(i != x && (t = a[i][y]))
{
a[i][y] = 0;
for(int j = 0; j <= n; j++)a[i][j] += t*a[x][j];
}
}
}
int simplex()
{
for(int x = 0, y = 0; ; x = y = 0)
{
for(int i = 1; i <= n; i++)if(a[0][i] > 0)
{
y = i;break;
}
if(!y)return a[0][0];
int inf = 2e9;
for(int i = 1; i <= m; i++)
{
if(a[i][y] < 0 && -a[i][0]/a[i][y] < inf)
{
inf = -a[i][0]/a[i][y];
x = i;
}
}
pivot(x, y);
}
}
int main()
{
freopen("employee.in", "r", stdin);
freopen("employee.out", "w", stdout);
n = fast_read();
m = fast_read();
for(int i = 1; i <= n; i++)a[0][i] = fast_read();
for(int i = 1; i <= m; i++)
{
int s, t, c;
s = fast_read();
t = fast_read();
c = fast_read();
for(int j = s; j <= t; j++)a[i][j] = -1;
a[i][0] = c;
}
printf("%d", simplex());
return 0;
}